nua7
1
Hi All,
Needa little help with sed and awk.
I have a file which contains password, Following is the sample:
<user username="tomcat" password="tomcat" roles="tomcat"/>
<user username="role1" password="tomcat" roles="role1"/>
<user username="both" password="tomcat" roles="tomcat,role1"/>
<user username="admin" password="admin" roles="admin,manager"/>
I need to pick up tomcat and admin values , basically what ever comes in " " after the word password, and replace it with some other text, say abcd.
Can someone please help me.
sed 's/\(password="\)[^"]*/\1abcd/' file
nua7
3
Guys..! Can someone please help!
nua7
4
Thanks a lot!! It's working!!
awk -v v="abcd" -v a='"' '
BEGIN{FS=OFS=a}
$2=="admin" {$4=v}
$2=="tomcat" {$4=v}
{print}' file
nua7
6
Radoluv:
Is it possible to maje changes in the original file using sed..?
If you have GNU Sed - yes (use the -i option),
or just change the interpreter
perl -i.bak -pe's/(password=").*?"/$1abcd"/' file
nua7
8
Hey! Thanks a lot for all the help!!
sed -i option did not work, but the perl command worked like a charm!