我需要编写一个shell脚本以插入换行符重新格式化文件。条件是在文件中遇到逗号时应插入换行符。
例如,如果文件
这能用
例如,如果文件
delimiter.txt
包含:
输出应该是:this, is a file, that should, be added, with a, line break, when we find, a comma.
this
is a file
that should
be added
with a
line break
when we find a
a comma.
这能用
grep
或awk
实现吗?
grep
可能是这项工作的合适工具。grep
的名称源自于g/re/p
,这些是搜索RE并打印匹配行的ed
命令。这就是grep的全部用途 - 搜索RE并打印结果,它不是一个编辑器。 - Ed Morton