开发者

Bash script. Insert a blank line before a number range

I need a bash script to format a text file. It must add a blank line before a range of numbers. Some开发者_运维百科thing like the examples in the images below. I am trying:

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

but it does't run.

Thanks in advance.

source screenshot

target screenshot


How would this work for you:

 sed '/^[0123456789]\+$/{x;p;x;}' < input.txt

From 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;}'
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜