On Sun, 13 Jul 2014 16:43:41 -0400
ESChamp <esch...@gmail.com> wrote:

> I apologize for having to ask this but my nearly-80-year-old brain
> just could not come up with a solution.
> 
> I have a text file consisting of several space-separated fields:
> 
> lastname firstname other other other ... emailaddress
> 
> I wish to write a new file that contains only the emailaddress field
> contents.
> 
> There's no need to test the emailaddress field.
> 
> I just need a quick and dirty solution as this will be used just one
> time.

Is the email address always the last field?

If so, a perl one-liner would do - using Perl's auto-split feature (the
-a) option:


$ perl -lane 'say $F[-1]' in.txt

That will read through the file, split the fields, and print the last
field of each line.

You can, of course, redirect the output to a new file using normal
shell redirection, e.g.:

$ perl -lane 'say $F[-1]' in.txt > out.txt



-- 
David Precious ("bigpresh") <dav...@preshweb.co.uk>
http://www.preshweb.co.uk/     www.preshweb.co.uk/twitter
www.preshweb.co.uk/linkedin    www.preshweb.co.uk/facebook
www.preshweb.co.uk/cpan        www.preshweb.co.uk/github



-- 
To unsubscribe, e-mail: beginners-unsubscr...@perl.org
For additional commands, e-mail: beginners-h...@perl.org
http://learn.perl.org/


Reply via email to