Regular expression question...

A

Andrew Munn

What is the best way to take each line beginning with <some_string> and move
it down 5 lines lower in the file?


Also, If you want to replace two consecutive blank lines with a single blank
line, how do you do it? This isn't working:
cat test_file.txt|sed -r 's/[\n\n]/[\n]/'


Thanks!!
 
R

rakesh sharma

Andrew Munn said:
What is the best way to take each line beginning with <some_string> and move
it down 5 lines lower in the file?

ex -s inputfile <<[EOF]
g/^regex/m+5
x
[EOF]

sed -e '/\n/G;/^regex/{h;N;N;N;N;N;D;}' inputfile

note: the outputs of ex and sed would diverge if the next /regex/ is found
within the first 5 lines. don't know how to make them same. some sed guru
is required for this.

Also, If you want to replace two consecutive blank lines with a single blank
line, how do you do it? This isn't working:
cat test_file.txt|sed -r 's/[\n\n]/[\n]/'

sed -e '/./!{$!N;/^\n$/s///;}' inputfile
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,755
Messages
2,569,537
Members
45,021
Latest member
AkilahJaim

Latest Threads

Top