regex - extracting chunk of string that matches regular expression using sed in unix -
suppose have bunch of urls , each url contains unique identifier. looks 'abc1000002'. has same leading string, 'abc', , number digits different.
the identifier occurs in various positions in urls,
http://www.examle.com?abc1000002 http://www.example.com?abc1000002=blahblah#3fdslfkj
i can write regular expression like, 'abc[0-9][0-9][0-9][0-9][0-9][0-9]..[0-9], how write sed command extract chunk matches regular expression?
grep
better tool job:
s='http://www.example.com/?abc1000002=blahblah#3fdslfkj' grep -eo 'abc[0-9]+' <<< "$s" abc1000002
Comments
Post a Comment