0

So I know how to use sed -i 's/string/new-string/g' *.* but I'm trying to change all references to a directory structure and I don't know the proper format for the command.

Example: I want to change 'myfolder/mysubfolder' to 'myfolder'.

So if there's a string in a file that says 'myfolder/mysubfolder/file.txt' I want it to say 'myfolder/file.txt'.

o_O
  • 5,527
  • 12
  • 52
  • 90

2 Answers2

2

You are on right track, just need to escape the /

sed -i 's/myfolder\/mysubfolder/myfolder/g' *.*
Amit
  • 19,780
  • 6
  • 46
  • 54
  • I figured it would be some kind of escape but didn't know if sed worked the same way. Thanks. – o_O Jan 22 '15 at 03:53
1
sed -i 's#myfolder/mysubfolder#myfolder#g' *.*

I used a delimiter other than / to avoid having to escape the / in the string.

Barmar
  • 741,623
  • 53
  • 500
  • 612