Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

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.

share|improve this question
There is grep -o that returns just the part you are looking for. – Eelvex Feb 28 '11 at 1:11
Why did you tag the question [microsoft-excel]? There's nothing about your question that has anything to do with that. – Dennis Williamson Feb 28 '11 at 1:14
@dennis: i left out the word excel from the last sentence but that was what i was referring to. – fightermagethief Feb 28 '11 at 1:34
up vote 2 down vote accepted

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.

share|improve this answer

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.

share|improve this answer

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.