1

The string is setup like so:

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

1
  • What shell are you talking about? Commented Nov 9, 2009 at 22:11

4 Answers 4

2

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
Sign up to request clarification or add additional context in comments.

Comments

2

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).

Comments

0
expr "$string" : 'href="\(.*\)">\[link\]'

Comments

0
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

2 Comments

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.
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]*

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.