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 strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

sed help 2

Status
Not open for further replies.

DrSmyth

Technical User
Jul 16, 2003
557
GB
Hi, I'm a bit rusty with my shell scripting and have a need to create a script to do the following:
Search a file for lines beginning with this string:
SITE_LIST_STR_PARM
Then for this line extract each of the numbers following it and put them in a new file each on a different line.

The numbers themselves have this string before them (which I'd like to delete):
"\\\'
with one of these two strings after them:
\\\'",
(which I'd like to replace with a carriage return)
or
\\\'"
(which I'd like to delete)

here's an example of the content of the file:
Code:
Testline
testline
SITE_LIST_STR_PARM="\\\'3607\\\'","\\\'9158\\\'","\\\'3160\\\'","\\\'2675\\\'"
other test line

what I'd like is for a new file to be created from this looking like this:
Code:
3607
9158
3160
2675

I've been playing around with the code for some time now and have come up with this:
Code:
#!/bin/ksh
sed -e s/SITE_LIST_STR_PARM/s/\\\'",/\n/g -e s/SITE_LIST_STR_PARM/s/"\\\'//g -e s/SITE_LIST_STR_PARM/s/\\\'"//g MyFile1.param > MyFile2.param

Which doesn't even parse... Was wondering if anyone could spot where I'm going wrong?

Cheers
 
for a quick and dirty solution:

grep SITE_LIST_STR_PARM= /path/to/file|\
tr -d "[A-Z]_=\\\'\"" |\
tr ',' '\n' > /path/to/newfile

I don't have the time right now to puzzle through your sed command strings. But I can tell you this: most sed implementations don't understand "\n".


HTH,

p5wizard
 
What about this ?
Code:
awk '/SITE_LIST_STR_PARM/{gsub(/[^0-9,]/,"");gsub(/,/,"\n");print}' MyFile1.param > MyFile2.param

Hope This Helps, PH.
FAQ219-2884
FAQ181-2886
 
Thanks PHV, works like a dream... Have a star
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top