Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Perl > Regular expression question...

Reply
Thread Tools

Regular expression question...

 
 
Andrew Munn
Guest
Posts: n/a
 
      06-29-2003
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!!




 
Reply With Quote
 
 
 
 
rakesh sharma
Guest
Posts: n/a
 
      06-30-2003
"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

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

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Seek xpath expression where an attribute name is a regular expression GIMME XML 3 12-29-2008 03:11 PM
C/C++ language proposal: Change the 'case expression' from "integral constant-expression" to "integral expression" Adem C++ 42 11-04-2008 12:39 PM
C/C++ language proposal: Change the 'case expression' from "integral constant-expression" to "integral expression" Adem C Programming 45 11-04-2008 12:39 PM
Matching abitrary expression in a regular expression =?iso-8859-1?B?bW9vcJk=?= Java 8 12-02-2005 12:51 AM
Dynamically changing the regular expression of Regular Expression validator VSK ASP .Net 2 08-24-2003 02:47 PM



Advertisments
 



1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57