On 17Jan2009 22:24, Matthew Flaschen <matthew.flaschen@xxxxxxxxxx> wrote: | Cameron Simpson wrote: | > On 17Jan2009 20:36, Matthew Flaschen <matthew.flaschen@xxxxxxxxxx> wrote: | > | Dave Stevens wrote: | > | > I have a sequence of lines of ASCII text of varying length, each of which ends | > | > with an integer. Anyone have a quick and dirty way of getting these lines | > | > copied to a new file with only the last number on each line of the new file? | > | | > | How about: | > | grep -o -E [[:digit:]]+$ foo.txt > new_file.txt | > | > I see your grep and raise you a sed: | > | > sed 's/.*[^0-9]//' foo.txt >new_file.txt | | 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, I raise you an awk, even more readable than the sed. awk '{print $NF}' foo.txt >new_file.txt 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... Cheers, -- Cameron Simpson <cs@xxxxxxxxxx> DoD#743 http://www.cskk.ezoshosting.com/cs/ But not in the World According to Microsoft where users are idiots and Wizards claim a monopoly on common sense. I want smart software, but if I can't have that, I want dumb software that knows it is dumb and comes to me for help, not dumb software that thinks it is smart and tells me lies it believes to be true. - jfieber@xxxxxxxxxxx in RISKS 20.63 on route planning software saying you can't get there from here -- fedora-list mailing list fedora-list@xxxxxxxxxx To unsubscribe: https://www.redhat.com/mailman/listinfo/fedora-list Guidelines: http://fedoraproject.org/wiki/Communicate/MailingListGuidelines