我想知道如何用 sed 单行打印出每个段落的第一个单词。在本例中,段落由 2 个换行符后面的文本定义。
e.g.
This is a paragraph with some text. Some random text that is not really important.
This is another paragraph with some text.
However this sentence is still in the same paragraph.
这应该转换为
This
This
Think
段落模式 http://gnu.org/software/gawk/manual/html_node/Multiple-Line.html
By a special dispensation, an empty string as the value of RS indicates that
records are separated by one or more blank lines.
awk
or perl
支持“段落模式”,两者都会比sed
:
awk '{ print $1 }' RS= ORS="\n\n" file
or
perl -00 -lane 'print $F[0]' file
Results:
This
This
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)