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

Replace with SED

Status
Not open for further replies.

rbri

Programmer
Jun 27, 2002
84
US
Hello Everyone
I am try to write a script that will change all the passwords in the passwd file to the same password. I have the script doing everything it needs until I encounter a password that has a "/" in it the SED substitution command fails because it gets to many slashes.
I can get a command to work at the command line to add a "\" in front of the slash so the command takes it a literal character and not apart of the SED command. Here is the command that works at the command line:
The PW: $1$HaERMTGs$GdCxR1AAHOvqBBOcE7vRL/ (The slash at the end messes up the SED command)
I put the PW in var1
The Command: echo $var1 | sed 's/\//\\\//g'
The new PW string: $1$HaERMTGs$GdCxR1AAHOvqBBOcE7vRL\/

For the script I need the new PW string in a variable I tried this:
sPw=`echo $sPw | sed "s/\//\\\//g"`
but the new string does not contain the "\" character I tried to replace the dbl quote marks with single quote marks in the SED command but then I get an error.
Does anyone know how to get the "\" character to appear in front of the slash in the variable or to get SED to ignore the "\" character in the variable and not think it is apart of the command. Any help would be greatly appreciated. Thank you for any help I can get.
 
Why not simply use another character than the / in your sed script ?
Anyway, why not post your script as awk may be more suitable than sed to change a password in the passwd file.

Hope This Helps, PH.
FAQ219-2884
FAQ181-2886
 
I tried your suggestion and used a different character than a "/" the script seems to be working now thank you for your help.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top