Computing.Net > Forums > Unix > seperating out a block of text

Computer Problems? Computing.Net has over 1,000,000 posts about all things technology related! Over 90% answered within 24 hours! Click here to start participating now! Also, be sure to check out the New User Guide.

seperating out a block of text

Reply to Message Icon

Name: AeroSpaceBalaji
Date: March 22, 2004 at 06:45:28 Pacific
OS: Solaris
CPU/Ram: P 3
Comment:

Hi Folks,

In a File (say F), I want to search first for a string (say A) and then search for (say B). Now i want the lines between A and B to be moved to another file say G.

Can anyone help me on this.

Thanks in advance...

ASB



Sponsored Link
Ads by Google

Response Number 1
Name: aigles
Date: March 22, 2004 at 07:18:20 Pacific
Reply:

Extract from sed FAQ

How do I address all the lines between RE1 and RE2, excluding
the lines themselves?

Normally, to address the lines between two regular expressions, RE1
and RE2, one would do this: '/RE1/,/RE2/{commands;}'. Excluding
those lines takes an extra step. To put 2 arrows before each line
between RE1 and RE2, except for those lines:

sed '1,/RE1/!{ /RE2/,/RE1/!s/^/>>/; }' input.fil

The preceding script, though short, may be difficult to follow. It
also requires that /RE1/ cannot occur on the first line of the
input file. The following script, though it's not a one-liner, is
easier to read and it permits /RE1/ to appear on the first line:

/RE1/,/RE2/{
/RE1/b
/RE2/b
s/^/>>/
}

A solution to your problem :

sed -n -e '/A/,/B/{
/A/b
/B/b
p
}' F > G

The same thing with awk

awk '/A/,/B/{ if (/A/ || /B/) next; print }' F > G


Jean-Pierre.


0
Reply to Message Icon

Related Posts

See More







Post Locked

This post is quite old and has been locked from receiving new replies. Please create a new posting instead.


Go to Unix Forum Home


Sponsored links

Ads by Google


Results for: seperating out a block of text

Sed - replace block of text - but h www.computing.net/answers/unix/sed-replace-block-of-text-but-h/7063.html

How to insert string in a list? www.computing.net/answers/unix/how-to-insert-string-in-a-list/7138.html

awk script to extract text www.computing.net/answers/unix/awk-script-to-extract-text/5899.html