Go Back   Velocity Reviews > Newsgroups > PERL
User Name
Password
Register FAQ Members List Calendar Search Today's Posts Mark Forums Read

Reply

PERL - Regular expression question...

 
Thread Tools Search this Thread
Old 06-29-2003, 10:15 PM   #1
Default Regular expression question...


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!!






Andrew Munn
  Reply With Quote
Old 06-30-2003, 03:11 AM   #2
rakesh sharma
 
Posts: n/a
Default Re: Regular expression question...

"Andrew Munn" <> wrote in message news:<bdnkvr$s0k$>...
> 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
  Reply With Quote
Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Forum Jump