Linux.com

Home Linux Community Forums Software Command Line help on regular expression

help on regular expression

Link to this post 29 Apr 13

hi,
I want to extract some URLs of a txt file with grep --only-matching and regular expression.

I know only some info about the URL, but I definitely know by what it is enclosed.
Example:
AA"$URL"BB

so I use grep -o AA.*BB myfile.txt

But this gives my whole expression (i.e. AA"$URL"BB), but I only want the URL i.e. what is enclosed by AA and BB, how do I do that?

Thanks.

Link to this post 12 May 13

sed 's/AA\(.*\)BB/\1/g' myfile.txt

Link to this post 14 May 13

Mfillpot, some help please

Link to this post 16 May 13

Rather than reposting data that is already on the net, I recommend checking out some of the posts at http://stackoverflow.com/questions/12522388/sed-awk-match-a-pattern-and-return-everything-between-the-end-of-the-pattern-a

In addition you may be able to find some other scripts that can help at http://www.commandlinefu.com

Who we are ?

The Linux Foundation is a non-profit consortium dedicated to the growth of Linux.

More About the foundation...

Frequent Questions

Join / Linux Training / Board