Sign up ×
Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.

I got a text file with contents like below

2012/03/15 : "Password":"@#4JF9u92r","Name":"John"

I wish to use sed to change the above to

2012/03/15 : "Password":"XXX","Name":"John"

I have tried the following command

cat log.txt | sed 's/\("Password":\"\)\(.*\)\(\",\"Name\":\)/\1XXX/'

But it gives me

2012/03/15 : "Password":"XXX"John"

What did I do wrong?


share|improve this question
Thanks to everyone :) –  forestclown Mar 16 '12 at 1:57

3 Answers 3

up vote 1 down vote accepted

You should slightly change your sed command:

sed 's/\("Password":\"\).*\(\",\"Name\":\)/\1XXX\2/'
share|improve this answer

This might work for you:

echo '2012/03/15 : "Password":"@#4JF9u92r","Name":"John"' |
sed 's/\("Password":"\)[^"]*/\1XXX/'
2012/03/15 : "Password":"XXX","Name":"John"
share|improve this answer
Thanks, this is more concise...but might not work if password contain the " character.. –  forestclown Mar 16 '12 at 1:56

Below regex is the base one, place necessary escape characters


Replace with \1XXX\3

After placing proper escape characters, I think it should be something like this.

cat log.txt | sed '\(s/\"Password\":\"\)\(.*?\)\(\",\"Name\":\"\(.*?\)\"\)/\1XXX\3/'
share|improve this answer

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.