views:

270

answers:

4

The string is setup like so:

href="PART I WANT TO EXTRACT">[link]

A: 
grep -o "PART I WANT TO EXTRACT" foo

Edit: "PART I WANT TO EXTRACT" can be a regex, i.e.:

grep -o http://[a-z/.]* foo
ctd
I'm using:> `grep -o 'http://[a-z/.A-Z0-9]*">\[link\]'`but it's giving me:> `http://img18.imageshack.us/img18/8079/69903601.jpg">[link]`I don't want the stuff on the end.
Josh
Well, you could grep to find, and then use grep -o to just get the expression: >grep 'http://[a-z/.A-Z0-9]*">\[link\]' | grep -o 'http://[a-z/.A-Z0-9]*
ctd
A: 
expr "$string" : 'href="\(.*\)">\[link\]'
ephemient
+2  A: 

use awk

$ echo "href="PART I WANT TO EXTRACT">[link]" | awk -F""" '{print $2}'
PART I WANT TO EXTRACT

Or using shell itself

$ a="href="PART I WANT TO EXTRACT">[link]"
$ a=${a//"/}
$ echo ${a/&*/}
PART I WANT TO EXTRACT
ghostdog74
A: 

Here's another way in Bash:

$ string="href="PART I WANT TO EXTRACT">[link]"
$ entity="""
$ string=${string#*${entity}*}
$ string=${string%*${entity}*}
$ echo $string
PART I WANT TO EXTRACT

This illustrates two features: Remove matching prefix/suffix pattern and the use of a variable to hold the pattern (you could use a literal instead).

Dennis Williamson