2

I am trying to use sed to remove these double backslashes in the front of this string so that this:

//s3.amazonaws.com/umdheader.umd.edu/app/js/main.min.js

will become:

s3.amazonaws.com/umdheader.umd.edu/app/js/main.min.js

so far I have it where it can remove one through the com

sed 's/^\///g' output 

but i need to remove two! please let me know thanks :)

SLePort
  • 15,211
  • 3
  • 34
  • 44
swiftcode123
  • 105
  • 5
  • 1
    you just had to add another ``\/`` ... see also: [How to use different delimiters for sed substitute command?](https://stackoverflow.com/questions/5864146/how-to-use-different-delimiters-for-sed-substitute-command) – Sundeep Jul 02 '18 at 14:52
  • @Sash, you could use following solution too by which you need not to escape `/` to remove its special meaning https://stackoverflow.com/a/51139804/5866580 – RavinderSingh13 Jul 02 '18 at 15:53
  • 1
    I don't understand how you could figure out that to remove `/` you use `\/` but couldn't make the leap to using `\/\/` to remove `//`. – Ed Morton Jul 02 '18 at 17:06
  • @EdMorton That's funny... a clever person who isn't clever enough to realise why the rest of us aren't as clever ;-) It kind of reminds me of the paradox about whether God is powerful enough to create a boulder that's so big he can't lift it. – Mark Setchell Jul 02 '18 at 19:00
  • 1
    @MarkSetchell IMHO you don't have to be clever to figure out that if X maps to Y then XX **might** map to YY and give it a try! :-) – Ed Morton Jul 02 '18 at 20:44
  • Again bulk down voting happened to all answers :( – RavinderSingh13 Jul 03 '18 at 11:56
  • 1
    @RavinderSingh13 I upvoted to restore. – SLePort Jul 03 '18 at 13:15

3 Answers3

2

You can try it this way with sed:

echo  "//s3.amazonaws.com/umdheader.umd.edu/app/js/main.min.js" | sed 's/^.*amazon/amazon/g'

or by regular expressions of variables

$ variable="//s3.amazonaws.com/umdheader.umd.edu/app/js/main.min.js"
$ echo ${variable#*//}
$ s3.amazonaws.com/umdheader.umd.edu/app/js/main.min.js
2

Or in case you don't want to escape / and simple want to substitute / starting ones with NULL then do following.

echo "//s3.amazonaws.com/umdheader.umd.edu/app/js/main.min.js" | sed 's#^//##'
RavinderSingh13
  • 130,504
  • 14
  • 57
  • 93
1

You can choose another delimiter than / in your command:

sed 's;^//;;' file

Or, if you want to escape the /:

sed 's/^\/\///' file
SLePort
  • 15,211
  • 3
  • 34
  • 44