我需要一个 bash 脚本来格式化一个文本文件。它必须在数字范围之前添加一个空行。 类似于下图中的示例。我正在尝试:
sed '1{x;d};$H;/^([1-9][0-9]{0,2}|[1-4][0-9]{3}|5000)$/{x;s/^/\n/;b};x '/home/name/zxc' > vvvv
但它没有运行。
提前致谢。
最佳答案
这对你有何作用:
sed '/^[0123456789]\+$/{x;p;x;}' < input.txt
来自 http://sed.sourceforge.net/sed1line.txt
# double space a file
sed G
# double space a file which already has blank lines in it. Output file
# should contain no more than one blank line between lines of text.
sed '/^$/d;G'
# triple space a file
sed 'G;G'
# undo double-spacing (assumes even-numbered lines are always blank)
sed 'n;d'
# insert a blank line above every line which matches "regex"
sed '/regex/{x;p;x;}'
# insert a blank line below every line which matches "regex"
sed '/regex/G'
# insert a blank line above and below every line which matches "regex"
sed '/regex/{x;p;x;G;}'
关于linux - bash 脚本。在数字范围前插入一个空行,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/7713947/