检查行是否以标点符号结尾; 如果没有,请添加期间

use*_*415 1 unix bash

我想检查一行是否以标点符号(.,?!)结尾,如果没有,则添加句点.

A button is missing!
A button on their back allowed them to hug
A cat is carried by the scruff of its neck by a teenage boy?
A cattery is where cats are commercially housed
Run Code Online (Sandbox Code Playgroud)

输出:

A button is missing!
A button on their back allowed them to hug.
A cat is carried by the scruff of its neck by a teenage boy?
A cattery is where cats are commercially housed.
Run Code Online (Sandbox Code Playgroud)

我真的很难过,我试着点击一个字符串的最后一个字符 - 任何帮助?

anu*_*ava 5

使用sed:

sed -i.bak 's/[^[:punct:]]$/&./' file
A button is missing!
A button on their back allowed them to hug.
A cat is carried by the scruff of its neck by a teenage boy?
A cattery is where cats are commercially housed.
Run Code Online (Sandbox Code Playgroud)

  • 我喜欢这不会改变空行. (2认同)