Reputation: 23
I'm trying to use sed to print just the last part of the url from a list of data. I want it to be using sed not awk.
Input data is like this:
Place,AF,http://en.wikipedia.org/wiki/Benin
Place Mat,NA,http://en.wikipedia.org/wiki/Saint_Barthelemy
Orion,NA,http://en.wikipedia.org/wiki/Bermuda
I want to just print the last part of the URL like this (WANT THIS):
Benin
Saint Barthelemy
Bermuda
I'm having so much trouble with the / and \ because they exist in the url!!!
My attempt so far (tryng to replace stuff I don't want with nothing)
sed -r s/$.+wikipedia\.org\/// in.txt
Also I need to replace spaces with _ but I can use the y command y/_/ / I think?
Upvotes: 2
Views: 1210
Reputation: 88601
With GNU sed:
sed 's/.*\///;s/_/ /g' file
or replace first s///
by s||||
to avoid escaping:
sed 's|.*/||;s/_/ /g' file
Output:
Benin Saint Barthelemy Bermuda
Upvotes: 2