Regular expression question...

Discussion in 'Perl' started by Andrew Munn, Jun 29, 2003.

  1. Andrew Munn

    Andrew Munn Guest

    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, Jun 29, 2003
    #1
    1. Advertising

  2. "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
     
    rakesh sharma, Jun 30, 2003
    #2
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Glenn Kidd

    Regular expression question

    Glenn Kidd, Aug 18, 2003, in forum: Perl
    Replies:
    0
    Views:
    949
    Glenn Kidd
    Aug 18, 2003
  2. Geoff Robinson

    Regular Expression Question

    Geoff Robinson, Nov 21, 2003, in forum: Perl
    Replies:
    2
    Views:
    423
    Geoff Robinson
    Nov 22, 2003
  3. VSK
    Replies:
    2
    Views:
    2,399
  4. =?iso-8859-1?B?bW9vcJk=?=

    Matching abitrary expression in a regular expression

    =?iso-8859-1?B?bW9vcJk=?=, Dec 1, 2005, in forum: Java
    Replies:
    8
    Views:
    886
    Alan Moore
    Dec 2, 2005
  5. GIMME
    Replies:
    3
    Views:
    12,053
    vforvikash
    Dec 29, 2008
Loading...

Share This Page