awk and sed-- need help

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

Guys..! Can someone please help!

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

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 :slight_smile:

perl -i.bak -pe's/(password=").*?"/$1abcd"/' file

Hey! Thanks a lot for all the help!!

sed -i option did not work, but the perl command worked like a charm!