sonriks
asked on
using a variable in a sed statement
I can't get this sed statement to work. Trying to use a variable. Any ideas?
cp /etc/shadow /etc/shadow.bak
OPASSWD=`grep ttc_root /etc/shadow.bak | awk -F: '{print $2}'`
(OPASSWD is the encrypted password, and may contain metacharacters)
sed -e 's/$OPASSWD/spoo/' /etc/shadow.bak
thanks
cp /etc/shadow /etc/shadow.bak
OPASSWD=`grep ttc_root /etc/shadow.bak | awk -F: '{print $2}'`
(OPASSWD is the encrypted password, and may contain metacharacters)
sed -e 's/$OPASSWD/spoo/' /etc/shadow.bak
thanks
ASKER
Thanks, Kent .. that worked like a charm for a "plain" string.
I need this to work for variables that contains metacharacters, as many entries in the shadow file do, characters like "/", "\", "$". etc.
OPASSWD=U/gx5Pid8Ykmk
Is there some way that the string with metachars being taken as a literal?
thanks
I need this to work for variables that contains metacharacters, as many entries in the shadow file do, characters like "/", "\", "$". etc.
OPASSWD=U/gx5Pid8Ykmk
Is there some way that the string with metachars being taken as a literal?
thanks
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
Thanks. I used a ":" as the delimiter and it worked fine!
sed -e "s/$OPASSWD/spoo/" /etc/shadow.bak
Kent