1753784 Members
6712 Online
108799 Solutions
New Discussion юеВ

Re: trouble with sed

 
SOLVED
Go to solution
Tom Wolf_3
Valued Contributor

trouble with sed

Hello, I have a text file named c01362 that contains the following information:


c01362:u_name=c01362:u_id#7043:\
:u_pwd=*:\
:u_auditid#21:\
:u_auditflag#1:\
:u_pswduser=c01362:u_suclog#1251142126:u_suctty=pts/tk:u_unsuclog#1239205577:\
:u_unsuctty=pts/tc:u_lock@:chkent:


I'm trying to use sed to replace the ":u_pwd=*:\" line with ":u_pwd=$tom:\" where $tom is a variable assigned the value 8675309.

The best I can get is this ":u_pwd=8675309*:\".
For some reason I can't get rid of the "*" character.

Here's the sed command I'm using

cat c01362 | sed -e "s~:u_pwd=*~:u_pwd=$tom~g"

When I try including the ":\" in the sed command (both with and without an escape character) I receive a "cannot be parsed" error as shown below.


cat c01362 | sed -e "s~:u_pwd=*:\\~:u_pwd=$tom:\\~g"
sed: Function s~:u_pwd=*:\~:u_pwd=8675309:\~g cannot be parsed.


cat c01362 | sed -e "s~:u_pwd=*:\~:u_pwd=$tom:\~g"
sed: Function s~:u_pwd=*:\~:u_pwd=8675309:\~g cannot be parsed.


Can anyone suggest how to replace the ":u_pwd=*:\" line within the text file I listed above with ":u_pwd=$tom:\"?

I'd really appreciate any assistance.

Thank you.

Tom
2 REPLIES 2
James R. Ferguson
Acclaimed Contributor
Solution

Re: trouble with sed

Hi Tom:

# tom=8675309
# sed -e "s~:u_pwd=\*~:u_pwd=$tom~g" c01362

That is, escape the * metacharacter.

Also, 'sed' reads its input from the command line. You don't need the extraneous 'cat' with a pipe. I love cats, but they have their place :-)

Regards!

...JRF...
Tom Wolf_3
Valued Contributor

Re: trouble with sed

Hello James, that worked perfectly.
I overlooked the obvious.

Thanks for the help.