Reputation: 211
Below my sample html file:
some text here <img src="http://site.com/7b399e20/77165/5fa/2a31ffb8.jpg"/> sometext here
some text here <img src="http://site.com/7b399e20/2a31ffb8.jpg"/> sometext here
some text here <img src="http://site.com/7b399e20/2a31ffb8.png"/> sometext here
some text here <img src="http://site.com/2a31ffb8.jpeg"/> sometext here
how do I make such a transformation:
some text here <img src="web/2a31ffb8.jpg"/> sometext here
some text here <img src="web/2a31ffb8.jpg"/> sometext here
some text here <img src="web/2a31ffb8.png"/> sometext here
some text here <img src="web/2a31ffb8.jpeg"/> sometext here
Thanks
Upvotes: 2
Views: 1817
Reputation: 3364
I'll use Perl, because I know the syntax without having to look it up, but it would be very similar in awk or sed, as tekknolagi says:
perl -pi -e 's|http://site.com/.*([^/]+)"/>|web/$1"/>|;' <filename>
This will preserve everything between the last / and the "
Upvotes: 3
Reputation: 430
What about using perl script? I have put your sample text into file foo.txt
and here is the result:
$ cat foo.txt | perl -pe 's#http://.*/([a-z0-9A-Z]*\.)#web/\1#'
some text here <img src="web/2a31ffb8.jpg"/> sometext here
some text here <img src="web/2a31ffb8.jpg"/> sometext here
some text here <img src="web/2a31ffb8.png"/> sometext here
some text here <img src="web/2a31ffb8.jpeg"/> sometext here
Upvotes: -1
Reputation: 51593
sed -i 's:\(img src="\).*\(/[^"/]\+\.[^"]\+"\):\1web\2:' INPUTFILE
Might do it in place.
HTH
Upvotes: 1