Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

SED-How to select single string only and not both? 2

Status
Not open for further replies.

RFC1795

IS-IT--Management
Feb 13, 2003
76
US
Hi,

I've searched the boards and not finding the answer to my problem. I'm probably using the wrong keywords ;-)

Anyhow, here's an example of the problem. As an example, I have a file which contains the following:

entry0/1
blah blah blah
#
entry0/12
other blah blah stuff
#
entry2/10
boring stuff here
#


Using sed I want to selectivly print the lines between the word "entryX/Y" and the symbol "#"

Eg:
root[/tmp] $ cat test.txt | sed -n "\?entry2/10?,/#/p"
Outputs:
entry2/10
boring stuff here
#


Thats good, now for the problem one:

root[/tmp] $ cat test.txt | sed -n "\?entry0/1?,/#/p"
Output:
entry0/1
blah blah blah
#
entry0/12
other blah blah stuff
#


I tried the sed man page but there doesn't seem to be a flag to say word only like grep -w for instance.

Any ideas?

Thanks..TJ
 
who knows - life is full with surprises ;)
He may be reading tek-tips from PC, copy/paste into 'textpad' [or some such] and ftp-ing the file to UNIX....
I don't know - the permutations are endless.

It was a simple and "obvious" warning.

vlad
+----------------------------+
| #include<disclaimer.h> |
+----------------------------+
 
Hi Futurelet, Vlad,

I tested it again , still gave me an error with awk , tried nawk and it worked fine (I did warn you I'm pretty useless when it comes to awk) :) So far so good.

Now, going back to my last post ... I think I'm having another problem which has been interfering with all of this. To you guys its probably a simple thing ... but for the life of me I have no idea how to sort it... think its a quote issue again.

If you look at the code bellow it might be obvious to you:
Script:
for AAA in `cat ABC.txt `
do
echo "----- $AAA -----"
nawk -v entry="$AAA" -f between.awk test.txt
done

File ABC.txt contains this as a test:
entry0/1
entry0/1 Adams,D.C
entry0/1.1 Adams,D.C
entry6/1.1
entry6/1.10
entry6/1.15 Adams,GK

Output from script run is:
----- entry0/1 -----
The data is:
address-code1
field1
----- entry0/1 -----
The data is:
address-code1
field1
----- Adams,D.C -----
----- entry0/1.1 -----
----- Adams,D.C -----
----- entry6/1.1 -----
The data is:
field1
----- entry6/1.10 -----
The data is:
Telxxxxxxx
Mobxxxxxxx
field1
----- entry6/1.15 -----
----- Adams,GK -----

I'm sure the problem is pretty clear to you ... any ideas how I get arround it?

Thanks for your time and assistance all.

TJ
 
between.awk
Code:
$0==entry{++f}
f{print;if(/^#/)--f}
Script
Code:
while read AAA
do
 echo "----- $AAA -----"
 nawk -v entry="$AAA" -f between.awk test.txt
done < ABC.txt

Hope This Helps, PH.
Want to get great answers to your Tek-Tips questions? Have a look at FAQ219-2884 or FAQ222-2244
 
Wow!!! I do believe that has solved my headache. Thanks PHV

I have no idea why that works and why the other way didn't ... don't care right now as I'm thrilled to see it working :)

Lovely stuff!! Thanks to all of you for your help, ideas and suggestions...

Cheers... TJ
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top