我有以下文本文件
config 'toto'
option
option
config 'titi'
list
list
config 'tutu'
list
list
当我用 cat
显示文件时,我想将每 2 行替换为一行。
我尝试了以下命令,但它们没有用
cat file | sed -e "s@$'\n'$'\n'@$'\n'@g"
cat file | sed -e "s@\n\n@\n@g"
预期的输出是这样的:
config 'toto'
option
option
config 'titi'
list
list
config 'tutu'
list
list
最佳答案
使用sed
:
sed '/^$/d' file
(或)
sed '/^[ ]*$/d' file
使用tr
:
tr -s '\n' < file
关于bash - 如何在文件中用一个替换 2 个新行,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22401277/