Just_RC
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.
<SYBASE>
Line to print
Line to print
Line to print
</SYBASE>
I've tried:
sed -n "s/\<SYBASE\>/,/\<\/SYBASE
Any comments would be appriciated.
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
Close. Very close. You want to search for the string, not substitute text within it.
sec -n '/\<SYBASE\>/,/\<\/SYBASE\
Good Luck,
Kent
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
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.
<SYBASE>
and
</SYBASE>
inclusive. Anything outside shouldn't be printed.
ASKER
I've doublechecked my syntax and I'm still dumping the entire file out to STDOUT.
None the less, thank you.
None the less, thank you.
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
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.
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>>
Must have been me escaping the '>'?
Wow...too cool Thank you.
sed -n "/\<SYBASE\>/,/\<\/SYBASE\
This should also work...
sed -n "/<SYBASE>/,/<\/SYBASE>/p"