Skip to main content

You are not logged in. Your edit will be placed in a queue until it is peer reviewed.

We welcome edits that make the post easier to understand and more valuable for readers. Because community members review edits, please try to make the post substantially better than how you found it, for example, by fixing grammar or adding additional resources and hyperlinks.

Required fields*

6
  • Thanks hek2mgl for the quick response! That was very quick. How can you do this repeatedly with first half of the string been static and second half keeps changing (as per question). I want to replace all strings in the file with similar format. 2nd string for example will look like uri='file:/var/lib/abc/cde.repo/t/e/s/t/v/1.9/zzz-1.9.jar' to be replace by 'uri='file:/lib/zzz-1.9.jar' Commented Nov 16, 2013 at 20:57
  • Try the following sed -re "s~uri='file:\S+/(\S+)'$~uri='file:/lib/\1'~g" file Commented Nov 16, 2013 at 21:02
  • 1
    @hek2mgl With nearly 23000 points here, you should know that sed can use different separator like this: sed "s~uri='file:/var/lib/abc/cde.repo/r/c/e/v/1\.1/abc-1.1.jar~uri='file:/lib/abc-1\.1\.jar~g" This way you do not need to escape all / Commented Nov 16, 2013 at 21:04
  • @Masti I have to leave for today. If you have patience until tomorrow I can help.. I guess the community might being faster.. :) Commented Nov 16, 2013 at 21:33
  • @Jotne I think text editing is a task for sed. Althought it is nicely possible with awk, sed should be used here. Or even xslt because regexes and html/xml aren't friends..... cu, and thanks for the ~ ... :) Commented Nov 16, 2013 at 21:34