[PLUG] Re: Okay after awk I need....

Wil Cooley wcooley at nakedape.cc
Sat May 7 21:04:25 UTC 2005


On Sat, 2005-05-07 at 06:03 -0700, Randal L. Schwartz wrote:
> >>>>> "Steve" == Steve D <blitters at gmail.com> writes:
> 
> Steve> cat names.txt | sed -e "s/^.*@//" | tee all.txt | sed -e
> Steve> "s/\(.*\)\.\(.*\)\.\(.*$\)/\2\.\3/" > domain.txt
> 
> If this had been comp.unix.questions, you would have been the
> winner of this week's "Useless Use Of Cat" award.
> <http://laku19.adsl.netsonic.fi/era/unix/award.html>

Hrm, certainly cat is unnecessary in this case, but when you start
chaining multiple pipes together like this, having your input clearly on
the left side and your output on the right makes the whole thing more
readable.  Of course, I guess that doesn't mean much to a Perl guru :-P

Of course, cat would indeed be unnecessary with a better, single sed
script (and I'm not sure what purpose the tee serves here):

$ sed -re 's/^.*[.@]([^.]+\.[^.]+)$/\1/' < names.txt > domain.txt

If not every line will actually be an address, you can only pull out the
ones that are:

$ sed -nre '/@/ { s/^.*[.@]([^.]+\.[^.]+)$/\1/; p }' < names.txt \
  > domains.txt

If you had a handful of three-level domains that you also wanted to get
(like *.co.uk), you could use a more strict RE than /@/ and separate the
processes based on a match like /@.*(co.uk|or.us)/, etc.


Wil
-- 
Wil Cooley                                 wcooley at nakedape.cc
Naked Ape Consulting                        http://nakedape.cc
* * * * Linux, UNIX, Networking and Security Solutions * * * *
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 189 bytes
Desc: This is a digitally signed message part
URL: <http://lists.pdxlinux.org/pipermail/plug/attachments/20050507/eb955f88/attachment.asc>


More information about the PLUG mailing list