3、初步体会sed的威力
比如你有一个文件内容如下:
test.txt:
{'books/daglib/0015113': '<title>Scale-isometric polytopal graphs in hypercubes and Z<sub>n</sub>.</title>\n',
'books/daglib/0097705': '<title>Discrete total l<sub>p</sub>-norm approximation problem for the function.</title>\n',
'books/daglib/p/AveneauCFM11': '<title>A Framework for <i>n</i>-Dimensional Visibility Computations.</title>\n',
'books/daglib/p/Carter11': '<title>Using <i>Dungeons and Dragons</i> to Integrate Curricula in Classroom.</title>\n',
'books/daglib/p/CasolaLRV11': '<title>Access Control in Cloud-on-Grid Systems: The <i>PerfCloud</i> Case Study.</title>\n',
'books/daglib/p/ChunKZDMZ11': '<title>Reverse Engineer of Gene Networks with Application <i>in silico</i> Network.</title>\n',
'books/daglib/p/ChungK11': '<title>eQTL Mapping for Functional Classes of <i>Saccharomyces cerevisiae</i> Genes wssion.</title>\n',
'books/daglib/p/Goldman11': '<title>A Model for Computer Graphics Based on Algebra for \xe2\x84\x9d<sup>3</sup>.</title>\n',
'books/daglib/p/LiZ11': '<title>Line Geometry over \xe2\x84\x9d<sup>3, 3</sup>, and Stewart Platforms.</title>\n',
'books/daglib/p/Liestol11': '<title><i>Situated Simulations</i> Between Reality and Designing a Narrative Space.</title>\n'}
现在你要将其中的各行中的类似于标签之类的东西去掉,只需用一条sed命令:
$sed -e 's/<title>//g;s/<\/title>//g' -e 's/<i>//g;s/<\/i>//g' -e 's/<sub>//g;s/<\/sub>//g' -e 's/<sup>//g;s/<\/sup>//g' test.txt
{'books/daglib/0015113': 'Scale-isometric polytopal graphs in hypercubes and Zn.\n',
'books/daglib/0097705': 'Discrete total lp-norm approximation problem for the function.\n',
'books/daglib/p/AveneauCFM11': 'A Framework for n-Dimensional Visibility Computations.\n',
'books/daglib/p/Carter11': 'Using Dungeons and Dragons to Integrate Curricula in Classroom.\n',
'books/daglib/p/CasolaLRV11': 'Access Control in Cloud-on-Grid Systems: The PerfCloud Case Study.\n',
'books/daglib/p/ChunKZDMZ11': 'Reverse Engineer of Gene Networks with Application in silico Network.\n',
'books/daglib/p/ChungK11': 'eQTL Mapping for Functional Classes of Saccharomyces cerevisiae Genes wssion.\n',
'books/daglib/p/Goldman11': 'A Model for Computer Graphics Based on Algebra for \xe2\x84\x9d3.\n',
'books/daglib/p/LiZ11': 'Line Geometry over \xe2\x84\x9d3, 3, and Stewart Platforms.\n',
'books/daglib/p/Liestol11': 'Situated Simulations Between Reality and Designing a Narrative Space.\n'}
如果要在原文件中修改,只需加-i参数。
