Perl或Bash脚本-文本文件中的前缀行以及文件中较早的文本 [英] Perl or Bash Script - Prefix Lines in text file with text from earlier in file
本文介绍了Perl或Bash脚本-文本文件中的前缀行以及文件中较早的文本的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有一个类似的文件:
!Denver
Line 1
Line 2
Line 3
!New York
Line 1
Line 2
我要执行以下操作-基本上拉带有前缀的文本!(例如!Denver)并附加文字,减去!"到下一行,直到另一行!随附用于前进行的新文本
I want to do the following - Basically pull the text with prefix ! ( like !Denver ) and append the text , less "!" to the next lines until another ! comes along with new text for proceeding lines
Denver.Line 1
Denver.Line 2
Denver.Line 3
New York.Line 1
New York.Line 2
这是更大脚本的一部分-但我希望自己完成其余的工作.
This is part of a bigger script - but am hoping to complete the rest myself.
我发现了以下内容:
所以我可能很快就会得到答案.
So I may get an answer myself shortly.
谢谢!
推荐答案
perl -ne 'if (s/^!//) { chomp; $p = $_ } elsif (/\S/) { print "$p.$_" }' < data
这篇关于Perl或Bash脚本-文本文件中的前缀行以及文件中较早的文本的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文