0

If I do have URLs like that

https:/www.sony.com/SonyInfo/News/Press/202004/20-0416E////
http:/www.sony.com.au/section/careers///
http:/www.sony.com.au/section/careers////
http:/www.sony.com.my/electronics/careers////
http:/www.sony.com.ph/electronics/careers////
http:/www.sony.com.sg/section/careers///

How can I remove the last slashes from the urls by using sed?

xibrahim
  • 5
  • 3

1 Answers1

0

I would do it following way, let file.txt content be

https:/www.sony.com/SonyInfo/News/Press/202004/20-0416E////
http:/www.sony.com.au/section/careers///
http:/www.sony.com.au/section/careers////
http:/www.sony.com.my/electronics/careers////
http:/www.sony.com.ph/electronics/careers////
http:/www.sony.com.sg/section/careers///

then

sed 's|/*$||' file.txt

gives output

https:/www.sony.com/SonyInfo/News/Press/202004/20-0416E
http:/www.sony.com.au/section/careers
http:/www.sony.com.au/section/careers
http:/www.sony.com.my/electronics/careers
http:/www.sony.com.ph/electronics/careers
http:/www.sony.com.sg/section/careers

Explanation: I use | as sed delimiter rather than / so I do not escape /, I replace zero-or-more (*) slash (/) immediately before end of line ($) using empty string, i.e. delete it

(tested in GNU sed 4.7)

Daweo
  • 31,313
  • 3
  • 12
  • 25