Velocity Reviews

Velocity Reviews (http://www.velocityreviews.com/forums/index.php)
-   Perl (http://www.velocityreviews.com/forums/f17-perl.html)
-   -   Regular expression question... (http://www.velocityreviews.com/forums/t24122-regular-expression-question.html)

Andrew Munn 06-29-2003 09:15 PM

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





rakesh sharma 06-30-2003 02:11 AM

Re: Regular expression question...
 
"Andrew Munn" <andrew60406@hotmail.com> wrote in message news:<bdnkvr$s0k$1@bob.news.rcn.net>...
> 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


All times are GMT. The time now is 08:03 PM.

Powered by vBulletin®. Copyright ©2000 - 2014, vBulletin Solutions, Inc.
SEO by vBSEO ©2010, Crawlability, Inc.