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,169
  • 12
  • 47
  • 88

2 Answers2

2

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

sed -i 's/myfolder\/mysubfolder/myfolder/g' *.*
Amit
  • 18,038
  • 6
  • 44
  • 52
  • 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
  • 669,327
  • 51
  • 454
  • 560