如何从ASCII文件的替换行中删除换行符 [英] How do I remove the line break from alternate lines in an ASCII file
本文介绍了如何从ASCII文件的替换行中删除换行符的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有一个ASCII文件,其中包含以下数据
I have an ASCII file that contains data as follows
459999XXX9998882 WTD CCD 3,500.00- 0.00 3,500.00- 0.00 0.00
09/07/17 23:00:07 999999999999 000000000000 EONCO024 GTUR BR AND PARDES APIN
459999XXX9998883 WTD CCD 400.00- 0.00 400.00- 0.00 0.00
09/07/17 23:00:12 999999999999 000000000000 EOMCO015 P.G ROAD, ANNA HOT SECU TLIN
29999XXX99988829 INQ CCD 0.00 0.00 0.00 0.00 0.00
09/07/17 23:00:41 999999999999 000000000000 EOMCO010 PUNA KUMBHARIA ROAD, SUR GJIN
5459999XXX999888 INQ SAV 0.00 0.00 0.00 0.00 0.00 UNABLE TO PROC
09/07/17 23:00:44 999999999999 000000000000 EONCO089 CTS NO 3985/5 ST STAND SOL MHIN
我希望包含日期的行与上方的行联系起来. Essenatilly我想从奇数行中删除所有换行符.结果就是这样
I would like lines containing the dates to be contactenated to the line above it. Essenatilly I would like to remove all the line breaks from odd numbered lines. So the result is something like this
459999XXX9998882 WTD CCD 3,500.00- 0.00 3,500.00- 0.00 0.00 09/07/17 23:00:07 999999999999 000000000000 EONCO024 GTUR BR AND PARDES APIN
459999XXX9998883 WTD CCD 400.00- 0.00 400.00- 0.00 0.00 09/07/17 23:00:12 999999999999 000000000000 EOMCO015 P.G ROAD, ANNA HOT SECU TLIN
29999XXX99988829 INQ CCD 0.00 0.00 0.00 0.00 0.00 09/07/17 23:00:41 999999999999 000000000000 EOMCO010 PUNA KUMBHARIA ROAD, SUR GJIN
5459999XXX999888 INQ SAV 0.00 0.00 0.00 0.00 0.00 UNABLE TO PROC 09/07/17 23:00:44 999999999999 000000000000 EONCO089 CTS NO 3985/5 ST STAND SOL MHIN
我尝试了此处提供的解决方案,但然后它删除了所有换行符,从而形成了一行!将不胜感激.
I tried the solution provided here but then it removed all the linebreaks resulting in one single line! Would appreciate any ideas.
推荐答案
sed 'N;s/\n/ /' ip.txt
-
N
将下一行添加到图案空间 -
s/\n/ /
将第一个换行符更改为空格(或任何分隔符) -
\n
的用法可能取决于sed
的实现.已在GNU sed
上进行了测试
N
add next line to pattern spaces/\n/ /
change first newline character to space (or whatever is the separator)- Usage of
\n
might depend onsed
implementation. This was tested onGNU sed
使用perl
,如果行号为奇数,请更改换行符
With perl
, change newline character if line number is odd
perl -pe 's/\n/ / if $.%2' ip.txt
也可以使用
Can also use
xargs -d'\n' -n2 -a ip.txt
-
-d'\n'
换行符作为分隔符 -
-n2
两行作为参数(空格用于合并它们) -d'\n'
newline character as delimiter-n2
two lines together as argument (space is used to combine them)
这篇关于如何从ASCII文件的替换行中删除换行符的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文