All new Registrations are manually reviewed and approved, so a short delay after registration may occur before your account becomes active.
Using regex in shell
Hi all!
I started to write a really small shell script, but i'm really stucked with a key part. I have a variable (multi line) and i would like to match only an url in it with regex. If i would use php, i would use preg_match. I read a lot, and found grep, which is not good for me (as i don't need the whole line), so i guess the only one working would be awk (correct me if i am wrong)
So please help me to find a regex pattern matcher in shell.
Code:
pastebin.com/TczfVMK2
Please grab the src=" part with shell regex into a variable (not a text file), that will give me the command i need.
Thank you!
PS: The code is just an example, you can send any kind of regex example, the important part is: it should find a matching pattern in a variable and output it into a variable. The matching pattern is not a whole line, only a little part in a long html/text document.
Comments
Please put your code on < pre > tags
Try something with 'sed'
(Or use perl)
ed is probably better.
although i still recommend you use php... there's a reason why they wrote parsers for php
There you go: http://www.math.utah.edu/docs/info/gawk_5.html
yeah awk is pretty strong.
it IS a little bit difficult to get going at first, but you'll be regex pro once you get the hang of it.
Something like this?
yeah, thanks for all. I thought sed is only to replace, but i will try it. Also i know gawk/awk is really good option, but currently i don't have time to learn it and just need a fast preg_match alternative.
sed/awk ftw.
And btw, there are different versions of awk. Some are faster than others, if you need to process heavy files.
while i'm stuck, and nothing i can do with my (shell/bash) script :
and start a new life after that..
And start a new life faster xD
grep
with the-o
option?Then a couple
sed
rules to chop off the attribute:OMFG! New tricks!
With enough piping, one can do almost anything in the world with a combination of
cat
,grep
,sed
,wc
,expr
, andseq
. (Or, alternatively, one can do almost anythingawk
can do with enough piping and some combination of those...)And actually, now that I have a little more time to look at this, I notice that really only one sed expression is needed if it uses a backreference:
(Yes, escaping is needed on the parentheses even though they're within single-quotes.)