[英]print line started by “F served..” in a multiple output file using “sed command”
I developed a script using sed
to retrieve lines starting by text F servedM..
from a given multilines file : 我使用
sed
开发了一个脚本来从给定的多行文件中检索以文本F servedM..
开头的行:
output.txt
containing all line starting by F servedMyd
and all lines starting by F servedPuid
. output.txt
包含由开始的所有行F servedMyd
并启动所有线路F servedPuid
。 I am using ksh on Red Hat 7.4. 我在Red Hat 7.4上使用ksh。
Below I give the code I tried. 下面我给出了我试过的代码。
#!/bin/ksh
input.txt=$1
while read line
do
sed "/^F servedMyd/p" $input.txt >> output.txt
sed "/^F servedPuid/p" $input.txt >> output.txt
done < $input.txt
exit 0
With this code, I didn't get any output. 有了这段代码,我没有得到任何输出。 I expected having an output file with the following structure:
我希望有一个具有以下结构的输出文件:
A script is unnecessary, a single line of sed
should be sufficient: 脚本是不必要的,单行
sed
就足够了:
sed -n '/^F served\(My\|Pui\)d/p' foo > bar
Or grep
: 或者
grep
:
grep '^F served\(My\|Pui\)d' foo > bar
Or: 要么:
grep -E '^F served(My|Pui)d' foo > bar
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.