OT: help with text file?

Matthew Flaschen matthew.flaschen at gatech.edu
Sun Jan 18 06:25:36 UTC 2009


Cameron Simpson wrote:
> | I see your sed and raise you an optimized but less readable grep.
> | 
> |     grep -oE [0-9]+$ foo.txt>new_file.txt
> 
> Hoping his numbers are whitespace delimited,

Never said that. ;)

>       awk '{print $NF}' foo.txt >new_file.txt

I don't think print $NF is particularly readable, but it's definitely a
matter of opinion. :)

> I'd point out that you need to do more shell quoting; if the OP has the
> misfortune to have a file called '3+$' lying around your grep won't do
> what you intend...

Ouch, bitten again by the vagaries of shell expansion.  Still, I have to
note that the grep with quoting:

grep -oE "[0-9]+$" foo.txt>new_file.txt

is still shorter than your sed (well, the same length if you drop the
space before the redir... ;))

Best,

Matt Flaschen




More information about the fedora-list mailing list