Sunday, April 6, 2008

Pattern matching with sed

My intention was to catch the blue part ::

[[tag_open]] href="blah%20blah.mp3">blah blah.mp3 [[tag_close]]

The following sed one liner does it perfectly ;) ...

wget -q -O - http://192.168.0.5:8000/ | grep mp3 | sed 's/.*href="\(.*\)".*/\1/'

The \( , \) and \1 are the key. The \1 prints that what is found between the \( and \).

another possible way is : grep -o PATTERN
another ... : awk -FS 'href=' :-p