Ask Ubuntu is a question and answer site for Ubuntu users and developers. It's 100% free.

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I have a config.xml file which shows:


How can I replace myUserId and myPass by using sed?

share|improve this question
replace myUserID and myPass with what? – Avinash Raj Apr 6 '14 at 17:05
with the argument I passed, let say I execute a shell script called "" ./ myname mypass – taymindis Woon Apr 6 '14 at 17:07
Do you know the initial value of myUserId and myPass or do you want to place your own values between the tags without knowing what the previous entries were? If so then you're looking for an xml parser. This Q&A might be helpful. – Glutanimate Apr 6 '14 at 17:38
What is the occurrence of those tags, do they appear only once on the entire file? – Lucio Apr 6 '14 at 18:12
How do I apply sed -n '/<serverName/,/<\/serverName/p' big_xml_file.xml In my scenario??how to replace it without knowing what was it? – taymindis Woon Apr 7 '14 at 0:06
sed "s/myUserId/$1/;s/myPass/$2/" originalfile 
share|improve this answer
Could you explain? – Braiam Apr 6 '14 at 17:56
if you run the script as: ./ ID PASS, then positional arguments $0, $1, $2 are ./, ID, PASS. Use ' ' for literals, and use " " for variables. s means substitute. – user3503167 Apr 6 '14 at 18:02
What if I don't know what was my userId and password in between tag? – taymindis Woon Apr 7 '14 at 0:08
probably you can use a regular expression, something like "<password>.*</password>" to match. – user3503167 Apr 7 '14 at 4:08

Solution Found

echo "cat //body/username" | xmllint --shell config.xml | sed '/^\/ >/d' | sed 's/<[^>]*.//g'

Can anyone explain this complex regex to me (^_^")

share|improve this answer
sed 's/old/new/g' test.txt > test1.txt
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.