1846882 Members
3966 Online
110256 Solutions
New Discussion

UNIX script

 
Robert_73
Occasional Advisor

UNIX script

Hi! list,
I am trying to write a parsing script, how do I remove &_requestid=808, number is different for request ids so 's/&request_id=//' is not going to work.
[05/Jun/2002:04:29:34 /index2.jhtml/myhome/index.jhtml&_requestid=808 "-"
[05/Jun/2002:04:49:41 /index2.jhtml/myhome/index.jhtml&_requestid=1048 "-"
[05/Jun/2002:07:14:38 /index2.jhtml/myhome/index.jhtml&_requestid=1676 "-"

Thanks in advance



UNIXDUDE
6 REPLIES 6
Rodney Hills
Honored Contributor

Re: UNIX script

How about
sed -e 's/&_requestid=.*//' outfile

This will remove everything past &_requestid

-- Rod Hills
There be dragons...
Tom Dawson
Regular Advisor

Re: UNIX script

Robert,

The regular expression "[0-9][0-9][0-9]" should match any string of three consecutive digits.

I'm not sure how well this will display, but there are no spaces between the double quotes. And the quotes would not be included in your search string.

And you'll probably have to escape the & with a backslash:

's/\&request_id=[0-9][0-9][0-9//'

HTH,
Tom
James R. Ferguson
Acclaimed Contributor

Re: UNIX script

Hi Robert:

You could use something like:

sed -e 's/&request_id=[[:digit:]]*//'

Regards!

...JRF...
Robert_73
Occasional Advisor

Re: UNIX script

Hi! list,
Thanks for the responses, but none of them are working.
This one will remove requestid and the other columns after that, I want to keep other columns
sed -e 's/&_requestid=.*//' outfile


Something like these commands should work but they are not working.

's/\&request_id=[0-9][0-9][0-9//'



sed -e 's/&request_id=[[:digit:]]*//'

Any help is appreciated.


UNIXDUDE
Tom Dawson
Regular Advisor

Re: UNIX script

Robert,

It looks like I had miss copied your test string. You had "_requestid" and I had copied it as "request_id". So now that I'm past that, here's what I did ( on a 10.20 system ):

I created a file called parsing.sed:

s/&_requestid=[[:digit:]]*//g

Then I executed sed with:

sed -f parsing.sed myfile > newfile

"myfile" was a cut and past of your test data above. Note that I've incorporated James' suggestion of using [[:digit:]]*. My first response would not have worked with numerical strings longer than three digits. I hadn't noticed that you had examples with more than three digits.

This worked okay for me with your test data. My "newfile" looks like this:

[05/Jun/2002:04:29:34 /index2.jhtml/myhome/index.jhtml "-"
[05/Jun/2002:04:49:41 /index2.jhtml/myhome/index.jhtml "-"
[05/Jun/2002:07:14:38 /index2.jhtml/myhome/index.jhtml "-"

HTH,
Tom
James R. Ferguson
Acclaimed Contributor

Re: UNIX script

Hi Robert:

I, too used the example of "request_id" and not your "requestid" string! Is that what you missed? Thy this:

# echo "my&requestid=808alpha\nyour&requestid=909beta"||sed -e 's/request_id=[[:digit:]]*//'

For output, you ahould have:

myα
yourβ

In the form using [0-9], you are missing a closing bracket "]" for the last part of the expression.

Regards!

...JRF...