我还有另一个bash
问题。如果我有像......这样的文件。
Today is sunny. I like the sun. It is awesome!
我希望打印出每个字符,直到它到达?
,.
或!
。这也可能是一个特殊的班轮吗?我希望打印输出看起来像。
Today is sunny.
I like the sun.
It is awesome!
答案 0 :(得分:2)
echo Today is sunny. I like the sun. It is awesome! | sed 's/[.!?] */&\n/g'
答案 1 :(得分:1)
您只需指定记录分隔符:
awk 'BEGIN {RS="[.!?] *"} {print}'
答案 2 :(得分:1)
awk中关闭的东西(不完全是需要但很有趣):
echo 'Today is sunny. I like the sun. It is awesome!'|awk '1' RS='[.,?]'
规范的awk方式:
echo 'Today is sunny. I like the sun. It is awesome!'|gawk 'a=gensub(/(\.|!|\?) */, "\\1\n", "g"){print a}'
答案 3 :(得分:1)
使用sed
的解决方案:
sed 's/\([\?\!\.]\)\s*/\1\n/g'
答案 4 :(得分:1)
echo Today is sunny. I like the sun. It is awesome! | awk '{gsub(/([?,.!])/,"&\n");print}'