Link to home
Start Free TrialLog in
Avatar of Just_RC
Just_RCFlag for United States of America

asked on

Range printing with sed.

I'm trying, in vain I'm afraid, to teach myself some sed.  I'd like to print a range of a data file.  My output sections in the data file are delimited (Using the 'SYBASE' section as an example:
<SYBASE>
Line to print
Line to print
Line to print
</SYBASE>
I've tried:
sed -n "s/\<SYBASE\>/,/\<\/SYBASE\>/p" notesfile

Any comments would be appriciated.

Avatar of amit_g
amit_g
Flag of United States of America image

An extra s must be the error ...

sed -n "/\<SYBASE\>/,/\<\/SYBASE\>/p" notesfile

This should also work...

sed -n "/<SYBASE>/,/<\/SYBASE>/p" notesfile
Hello Just_RC,

Close.  Very close.  You want to search for the string, not substitute text within it.

sec -n '/\<SYBASE\>/,/\<\/SYBASE\>/p' notesfile


Good Luck,
Kent
Avatar of Just_RC

ASKER

Amit g:
Closer....it dumps the entirety of the 'notesfile'.  My intention was just to print the lines between the range definitions...in your understanding, isn't that what the '-n' switch does?

Thank you for your time and attention.

RC
It should only print the lines between

<SYBASE>

and

</SYBASE>

inclusive. Anything outside shouldn't be printed.
Avatar of Just_RC

ASKER

I've doublechecked my syntax and I'm still dumping the entire file out to STDOUT.

None the less, thank you.
ASKER CERTIFIED SOLUTION
Avatar of amit_g
amit_g
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of Just_RC

ASKER

OS/Hardware: Solaris 5.6 on SPARCstation-5
sed -n "notesfile -->Unrecognized Command
sed -n 'p' notesfile --> Dumps entire file
sed -n '1,5p' notesfile --> Dumps first 5 lines of file (Same as head -5 notesfile)
sed -n '/<SYBASE>/p' notesfile --> Dumps '<SYBASE>'
sed -n'/<SYBASE>/,/<\/SYBASE>>/p' notesfile --> Whoohoo...

Must have been me escaping the '>'?

Wow...too cool Thank you.