我已经这样了:
'< Jan 20 Sep> This is the sample out put
This is Sample
>
'< Jan 21 Sep> This is the sample out put
This is Known Errors
>
所以我需要从文件中删除所有 > 特殊字符。仅需要删除存在一个特殊字符 > 的行。我想要下面的输出
'< Jan 20 Sep> This is the sample out put
This is Sample
'< Jan 21 Sep> This is the sample out put
This is Known Errors
答案1
如果“>”字符出现在问题中所示的单行中,您可以:
grep -wv '>' thefile
结果:
'< Jan 20 Sep> This is the sample out put
This is Sample
'< Jan 21 Sep> This is the sample out put
This is Known Errors
答案2
这将删除>
每行开头的字符并将输出打印到 STDOUT。如果要将输出写入文件,则需要使用-i
选项或重定向输出。sed
sed 's%^>%%' <filename>
例如,您可以使用此命令进行测试
% sed 's%^>%%' <<'EOF'
'< Jan 20 Sep> This is the sample out put
This is Sample
>
EOF
结果
'< Jan 20 Sep> This is the sample out put
This is Sample
答案3
这些命令应该可以完成您正在寻找的内容。
command | sed '/^ \?> \?$\|^$/d'
或者
sed '/^ \?> \?$\|^$/d' file.txt
正则表达式读起来像这样。
任何匹配的东西/pattern/
>
包含且带有可选的前置或尾随空格的行^ \?> \?$
或者\|
为空^$
删除它d