0

I want to replace the host id in number of files and the host id is different in each file, so I have to replace the content between the tags <hostid> and </hostid>, each file has only one <hostid> line

<hostid>71342-231VMKDK-47WW-03dMV6</hostid>

to

 <hostid>xxxx-yyyyy-zzz-uuu-bb</hostid>

I did try something like below which didn't work

sed -i "" -e :a -e 's/\(hostid>[X]*\)[^X]\(.*<\)/\1\something\</;ta' 
3
  • Please do add your efforts which you have put to solve your own problem in your post and let us know then. Commented Jun 12, 2019 at 1:34
  • 1
    I did try my level best but I'm not good with sed Commented Jun 12, 2019 at 1:58
  • Not an issue, we do encourage all users to add their efforts either wrong or right that is not an issue, I did add 1 answer let me know if that is helpful, cheers. Commented Jun 12, 2019 at 2:01

1 Answer 1

1

Could you please try following.

sed '/hostid/s/>.*</>xxxx-yyyyy-zzz-uuu-b</'  Input_file

In case you want to save output into Input_file itself along with taking backup of Input_file then change sed to sed -i.bak ....

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.