0

grep/egrep 中是否有办法从该文本中提取棘手的模式,将它们插入行的开头及其剩余行,使其看起来如下所示?

从许多包含“非特定”一词的文件中提取的原始文本。现在我需要组织这些,使名称从行首开始,以便于阅读。在它们之间插入一个空行也会有所帮助,但这在 egrep 中可能是不可能的?

输入:

SofasCouchesChairs/Type1234567.xml:Nonspecific Couch-W ISSUESTablesDesks/Type123765.xml:Nonspecific Tables issues BedsDivans/Type4567345.xml:Nonspecific bed abnormalitiesBedBugs/Type2893993.xml:Nonspecific bugs in the spring boxes related to the mattressBed_Sofas/Type1317994.xml:Nonspecific WR abnormalities these are from Radios_TV/Type1274978.xml:radiation perhaps with nonspecific cell phones and cell towers Cabinets_TelephoneWires/Type1299691.xml:DATA:all kinds of nonspecific cell phone wave changes, with a 

预期输出:

SofasCouchesChairs/Type1234567.xml:Nonspecific Couch-W ISSUES

TablesDesks/Type123765.xml:Nonspecific Tables issues 

BedsDivans/Type4567345.xml:Nonspecific bed abnormalities

BedBugs/Type2893993.xml:Nonspecific bugs in the spring boxes related to the mattress

Bed_Sofas/Type1317994.xml:Nonspecific WR abnormalities these are from 

Radios_TV/Type1274978.xml:radiation perhaps with nonspecific cell phones and cell towers

Cabinets_TelephoneWires/Type1299691.xml:DATA:all kinds of nonspecific cell phone wave changes, with a 
4

1 回答 1

1

看评论; 输入实际上是:

SofasCouchesChairs/Type1234567.xml:Nonspecific Couch-W ISSUES
TablesDesks/Type123765.xml:Nonspecific Tables issues 
BedsDivans/Type4567345.xml:Nonspecific bed abnormalities
BedBugs/Type2893993.xml:Nonspecific bugs in the spring boxes related to the mattress
Bed_Sofas/Type1317994.xml:Nonspecific WR abnormalities these are from 
Radios_TV/Type1274978.xml:radiation perhaps with nonspecific cell phones and cell towers
Cabinets_TelephoneWires/Type1299691.xml:DATA:all kinds of nonspecific cell phone wave changes, with a

您可以将输出加倍以匹配预期输出:

sed G input.txt > output.txt

顺便说一句,如果您想让事情更容易阅读,您可以尝试 G 的数量。例如,这将使您的文件空间增加三倍:

sed G;G input.txt > output.txt

此外,要直接对您的文件进行更改,您可以使用该-i标志(这使我们不必不必要地创建output.txt):

sed -i G input.txt
于 2012-08-14T03:35:26.897 回答