Regular expression question...

Regular expression question...

Post by Andrew Mun » Tue, 01 Jul 2003 06:15:02



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

 
 
 

Regular expression question...

Post by rakesh shar » Tue, 01 Jul 2003 11:11:52



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

Quote:

> 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

 
 
 

1. regular expression question

1.  Is there a unix FAQ?? I couldn't find one.

2.  Given the definition for regular expressions in the ed appendix
    in the Kernighan and Pike book, is there such a thing as
    an expression which is not a regular expression (i.e. are
    there irregular expressions...) if so, what would be an
    example of one?

Someone actually asked me the question.  I'm of the opinion that
they don't exist.

__________________________________________________________________

Debi Kipping


2. LPD - Printing - need help, please!

3. Regular Expression Question

4. resolution on laptop

5. A simple regular expression question

6. Apache, jserv and logging

7. Grep: Regular Expression question

8. ApplixWare: Equation editing

9. Regular Expression Question

10. regular expression question

11. Yet another regular expression question ...

12. Regular expression question...

13. simple vi and regular expression question.