Windows环境下sed的正确方法
我有以下 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 [email protected]//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 ,[email protected],,//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,[email protected]//g;" ConedScrape_494202320000008.txt
I have the following sed which works perfect but I do not like the flow because it outputs the result every line. The second portion of code represents what I am trying to consolidate but the output is not correct. Can anyone assist? This piece of code in the second portion is throwing my result out of wack -i -e ":a;N;$!ba;s/\n/ /g" it works fine in the top code but i can not add it in the second code witout writing out the result set. I am just trying to write this correctly.
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 [email protected]//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 ,[email protected],,//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
second Portion of code.
@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,[email protected]//g;" ConedScrape_494202320000008.txt
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
如果您有大量 sed 命令,可以将它们放入一个文件中并使用:
If you have a large number of sed commands, you can put them into a file and use: