我正在从远程系统获取消息,响应是多行的,我必须将其转换为基于分隔符的单行。
流阅读器的内容如下
Iam in first Line
Iam in second Line
:
Iam in third Line
Iam in the forth Line
Iam in fifth Line
:
Iam in Sixth Line
Iam In seventh Line
IAm in Eighth Line
:
响应的多行应转换为单行,直到分隔符":“
请注意,im从远程系统读取它,而不是从文件读取,它是连续的,并且没有eof.until。与远程系统的连接终止
输出应为:
Iam in first Line Iam in second Line:
Iam in third Line Iam in the forth Line:
Iam in Sixth Line Iam In Seventh Line Iam in Eighth Line:
有没有人能帮我想个办法或命令来实现这个目标?
发布于 2012-11-09 13:04:59
一种方法:
$ perl -pne 'chomp unless(/^:/);' file
Iam in first LineIam in second Line:
Iam in third LineIam in the forth LineIam in fifth Line:
Iam in Sixth LineIam In seventh LineIAm in Eighth Line:
发布于 2012-11-09 14:13:09
perl -p -e 's/\n/ /g;s/:[\s]*/:\n/g' your_file
测试如下:
> cat temp
Iam in first Line
Iam in second Line
:
Iam in third Line
Iam in the forth Line
Iam in fifth Line
:
Iam in Sixth Line
Iam In seventh Line
IAm in Eighth Line
:
> perl -p -e 's/\n/ /g;s/:[\s]*/:\n/g' temp
Iam in first Line Iam in second Line :
Iam in third Line Iam in the forth Line Iam in fifth Line :
Iam in Sixth Line Iam In seventh Line IAm in Eighth Line :
>
https://stackoverflow.com/questions/13302301
复制相似问题