1

i have a text file where each line looks like this:

<img border=0 width=555 height=555 src=http://websitelinkimagelinkhere>  

each line is like that for like 1500 lines, i want to sort of 'grep' (i dont think that will work because it returns the whole line) each line for 'http://websiteimagelinkhere'
output file should have newlines or tabs after each image link, like the original file.
or if someone only knows a way to do this with each element being in a cell of the same column that would be okay too.

3
  • There is grep -o that returns just the part you are looking for.
    – Eelvex
    Feb 28, 2011 at 1:11
  • Why did you tag the question [microsoft-excel]? There's nothing about your question that has anything to do with that. Feb 28, 2011 at 1:14
  • @dennis: i left out the word excel from the last sentence but that was what i was referring to. Feb 28, 2011 at 1:34

2 Answers 2

2

If it's one per line:

sed 's/.*src=\([^>]*\)/\1/' inputfile

should get it.

Are there quotes around the URL? If so:

sed 's/.*src="\([^"]*\)/\1/' inputfile

If you have GNU grep:

grep -Po '.*?src="\K.*?(?=">)' inputfile

Leave out the quotes if there aren't any around the URL. The grep version will work even if there are more than one URL on a line.

0

If you want to use Excel to put each element in its own cell, then use Data > Text to Columns….

Then use -space- as a delimiter. In your example, you'll end up with five columns in each row.

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .