我有以下sed工作完美,但我不喜欢流程,因为它每行输出结果。代码的第二部分代表我想要整合的内容,但输出不正确。有人可以帮忙吗?第二部分中的这段代码将我的结果抛出了wack -i -e“:a; N; $!ba; s / \ n / / g”它在顶级代码中工作正常但我无法添加它在第二个代码中没有写出结果集。我只是想正确地写这个。
sed -i "1,275d" ConedScrape_494202320000008.txt
sed -i -r "s/>/>~/g; s/</~</g;" ConedScrape_494202320000008.txt
sed -i -r "s/~~//g" ConedScrape_494202320000008.txt
sed -i -e :a -e "s/<[^>]*>//g;/</N;//ba" ConedScrape_494202320000008.txt
sed -i "s/\s/\n/g" ConedScrape_494202320000008.txt
sed -i -n -e ":a" -e "$ s/\n/ /gp;N;b a" ConedScrape_494202320000008.txt
sed -i -e "s/^[ \t]*//" ConedScrape_494202320000008.txt
sed -i -e "s/\r//" ConedScrape_494202320000008.txt
sed -i -e "s/ */,/g; s/--*/--,/g" ConedScrape_494202320000008.txt
sed -i -e "s/ //g; s/If you have any problems or questions please contact us at ~RETAILACCESS@Coned.Com//g;" ConedScrape_494202320000008.txt
sed -i -r "s/,//g; s/~~,/,/g; s/~~/,/g;" ConedScrape_494202320000008.txt
sed -i -r "s/, /,/g; s/,~/,/g;" ConedScrape_494202320000008.txt
sed -i -r "s/,,/,/g; s/~ ,//g;" ConedScrape_494202320000008.txt
sed -i -r "s/,,/,/g" ConedScrape_494202320000008.txt
sed -i -r "s/,, , , ,If you have any problems or questions please contact us at ,RETAILACCESS@Coned.Com,,//g" ConedScrape_494202320000008.txt
sed -i -r "s/,,/,/g; s/, ,//g; s/,Tension Code,Stratum Variable,ICAP,PFJ ICAP,Residential %%,LBMP Zone//g; s/,Trip Number,Service Class,Previous Account Number,Min Monthly Demand,TOD Code,Profile,Tax,Muni//g; s/,From Date,To Date,Use,Demand,Bill Amt//g;" ConedScrape_494202320000008.txt
sed -i -r "s/, //g;" ConedScrape_494202320000008.txt
第二部分代码。
@echo off
sed -i -e "1,275d" ^
-r -e "s/>/>~/g; s/</~</g;" ^
-e "s/~~//g" ^
-e :a -e "s/<[^>]*>//g;/</N;//ba" ^
-e "s/\s/\n/g" ConedScrape_494202320000008.txt
sed -i -e ":a;N;$!ba;s/\n/ /g" ConedScrape_494202320000008.txt
sed -i -e "s/^[ \t]*//" ^
-e "s/\r//" ^
-e "s/ */,/g; s/--*/--,/g" ^
-e "s/,//g; s/~~,/,/g; s/~~/,/g;" ^
-e "s/\n/ /g;" ^
-e "/^$/d" ^
-e "s/^\([^,]*,\)\{2\}//" ^
-e "s/,Tension Code,Stratum Variable,ICAP,PFJ ICAP,Residential %%,LBMP Zone//g" ^
-e "s/,Trip Number,Service Class,Previous Account Number,Min Monthly Demand,TOD Code,Profile,Tax,Muni//g" ^
-e "s/,From Date,To Date,Use,Demand,Bill Amt//g;" ^
-e "s/, /,/g;" ^
-e "s/ ,/,/g;" ^
-e "s/,,//g;" ^
-e "s/, , ,If you have any problems or questions please contact us at,RETAILACCESS@Coned.Com//g;" ConedScrape_494202320000008.txt
答案 0 :(得分:1)
如果您有大量的sed命令,可以将它们放入文件中并使用:
$ cat script.sed
s/foo/bar/g
s/xxx/yyy/g
$ sed -i -f script.sed data.txt