[ALUG] Regex Help

Brett Parker iDunno at sommitrealweird.co.uk
Tue Jul 13 16:47:14 BST 2010


On 13 Jul 16:28, Richard Parsons wrote:
> Friends,
>
> I admit that I am terrible with regex.  I need a script to output all  
> words beginning with "$" from a text file.  Here's what I've got so far:
>
> cat file.txt | grep "$" | sed <some-regex>

How about:

    sed -e 's#[^$]*\(\$[^[:space:]]*\)#\1 #g; s#\(.*\)\([$][[:alpha:]]*\).*$#\1\2#; s# #\n#g;' file.txt

Cheers,
-- 
Brett Parker



More information about the main mailing list