我有一个文件,该文件包含以下内容:awk的前追加新行结束线的匹配模式
TTITLE0=Dispenser (Unreleased, 1995)
TTITLE1=Pivotal (From The Icebreaker 7", 1998)
TTITLE2=Sucker & Dry (From the Sucker & Dry 7", 1997)
TTITLE3=Icebreakers (From The Icebreaker 7", 1998)
TTITLE4=And The Bit Just Chokes Them (From the Sucker & Dry 7", 1997)
TTITLE5=There's A Coldest Day In Every Year (From The Disruption 7", 1
TTITLE5=996)
TTITLE6=A Disruption In The Normal Swing Of Things (From The Disruptio
TTITLE6=n 7", 1996)
TTITLE7=Nostalgia (From the Makoto Split 7" Series w/Small Brown Bike,
TTITLE7= 2001)
TTITLE8=The Knowledgeable Hasbeens (From The Disruption 7", 1996)
TTITLE9=Polar (From The Icebreaker 7", 1998)
TTITLE10=A Disruption In Our Lines Of Influence (From The Disruption 7
TTITLE10=", 1996)
TTITLE11=I Thought There'd Be More Than This (Unreleased, 1996)
正如你可以看到,当曲目的标题过长,标题附加在下一行,前面有TTITLE(samenumber)=
。我需要做的是使这些长期的标题一行。
我的进攻计划是确定开始的行的匹配,增加一个反斜杠第一两个结束,使用
cut -d"=" -f 2
删除
TTITLE(num)=
然后将第二行添加到第一行使用着名的awk
单线程
awk '/\\$/ { sub(/\\$/,""); getline t; print $0 t; next }; 1'
测试一下,如果我手动添加反斜杠并删除TTITLE
与cut
,awk
声明完美地工作。另一方面,如果有人有更好的主意,请分享!
我宁愿使用awk
或sed
因无力安装在机器perl
或ruby
这将是上运行,但是,如果这是唯一的解决办法,我可以使它发挥作用。
这就是我所需要的,+1为了超越第二个例子。 – rick 2011-05-16 04:53:41
我不需要'BEGIN'部分,因为在'awk'中,未初始化的变量将被解析为''“'无论如何:'awk -F”=“'$ 1 == prev_title {printf”%s“,$ 2;下一个} {prev_title = $ 1} NR == 1 {printf“%s”,$ 0; next} {printf“\ n%s”,$ 0} END {print“”}'' ' – mschilli 2013-09-02 13:54:27