我已经通过命令提取了数据并将其保存在 kwrite 文件中,但现在我想从中检索一些重要数据,但理想情况下数据应该在 1 行,而在我的例子中,它分成 2、3 行。以 Jpak 开头的行是值得关注的。数据:
Jpak= its just a sample data for posting,
solve the query asap
Breadth=44
***** less*****
--
Effective search space used: 2418848120
Jpak= To work late into the night, alluding to the
time before electric lighting
Breadth=75
***** less*****
--
Jpak= Speak of an issue, (mostly current) which ,
many people ,
are talking
Breadth=22
***** less *****
- -
期望输出:
Jpak= its just a sample data for posting solve the query asap
Jpak= To work late into the night alluding to the time before electric lighting
Jpak= Speak of an issue (mostly current) which many people are talking
答案1
纯sed
溶液
抱歉,我对不太熟悉awk
,但是这可以完成工作:
sed '/Jpak=/,/^$/!d' sample|sed ':a;N;$!ba;s/\n//g;s/,/ /g;s/ \{2,\}/ /g;s/Jpak/\n\nJpak/g'
聚集在一起sed1行和如何使用 sed 替换换行符 (\n)?。
输出
Jpak= its just a sample data for posting solve the query asap
Jpak= To work late into the night alluding to the time before electric lighting
Jpak= Speak of an issue (mostly current) which many people are talking
使用此命令链,输出以两个空行(此处未显示)开始,添加到|sed '1,2d'
链的末尾以删除它们。
答案2
perl -n00E '/Jpak=/ and s/\s+/ /g and say' ex.txt
-n00E
-- 对于每个以空行分隔的段落执行.../Jpak=/ and
——找到所需的模式并……s/\s+/ /g
-- 用单个空格替换空格、换行符和制表符序列and say
——并说出发现了什么。
输出为:
Jpak= its just a sample data for posting, solve the query asap
Jpak= To work late into the night, alluding to the time before electric lighting
Jpak= Speak of an issue, (mostly current) which , many people , are talking