Solved

Range printing with sed.

Posted on 2007-04-04
7
1,242 Views
Last Modified: 2008-01-09
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.

0
Comment
Question by:Just_RC
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 3
  • 3
7 Comments
 
LVL 58

Expert Comment

by:amit_g
ID: 18853351
An extra s must be the error ...

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

This should also work...

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

Expert Comment

by:Kent Olsen
ID: 18853373
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
0
 
LVL 2

Author Comment

by:Just_RC
ID: 18853389
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
0
Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
LVL 58

Expert Comment

by:amit_g
ID: 18853410
It should only print the lines between

<SYBASE>

and

</SYBASE>

inclusive. Anything outside shouldn't be printed.
0
 
LVL 2

Author Comment

by:Just_RC
ID: 18853737
I've doublechecked my syntax and I'm still dumping the entire file out to STDOUT.

None the less, thank you.
0
 
LVL 58

Accepted Solution

by:
amit_g earned 50 total points
ID: 18853773
What *nix you have?

Could you try these command individually and let us know what you get from each one of them?

sed -n '' notesfile
sed -n 'p' notesfile
sed -n '1,5p' notesfile
sed -n '/<SYBASE>/p' notesfile
sed -n '/<SYBASE>/,/<\/SYBASE>/p' notesfile
0
 
LVL 2

Author Comment

by:Just_RC
ID: 18853881
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.
0

Featured Post

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

In tuning file systems on the Solaris Operating System, changing some parameters of a file system usually destroys the data on it. For instance, changing the cache segment block size in the volume of a T3 requires that you delete the existing volu…
A metadevice consists of one or more devices (slices). It can be expanded by adding slices. Then, it can be grown to fill a larger space while the file system is in use. However, not all UNIX file systems (UFS) can be expanded this way. The conca…
Learn several ways to interact with files and get file information from the bash shell. ls lists the contents of a directory: Using the -a flag displays hidden files: Using the -l flag formats the output in a long list: The file command gives us mor…
Learn how to navigate the file tree with the shell. Use pwd to print the current working directory: Use ls to list a directory's contents: Use cd to change to a new directory: Use wildcards instead of typing out long directory names: Use ../ to move…

732 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question