[PLUG] edit lines in a text file
Paul Heinlein
heinlein at madboa.com
Tue Mar 29 20:06:54 UTC 2005
On Tue, 29 Mar 2005, Steve Bonds wrote:
> On Tue, 29 Mar 2005 11:36:33 -0800, Maodhog wrote:
>
>> I want to take a text file, made up of email addresses and chop the
>> users name off the domain name so I can uniq -u the domains.
>>
>> I can't remember what the command is to remove all before the
>> character "X"(which in this case is the @ sign).
>
> awk -F@ '{print $2}' < your_file
> perl -p -e 's/^[^\@]+\@//' < your_file
> perl -n -e 'chomp; if (/\@(.*)$/) { print "$1\n" }' < your_file
sed 's!^.*@!!' your_file
cut -d@ -f2 < your_file
I find that GNU sed is typically faster than any other solution, but
the real time difference is probably insignificant in a job like
yours.
Oh, to sort the domain names in a way that takes subdomains into
account, try
sed 's!^.*@!!' your_file | sort -t. -k 3,3 -k 2,2 -k 1,1 | uniq
This recipe assumes no more than 3 levels of subdomains in any given
address. I assume you can figure out how to adjust the recipe if you
know that you have more or fewer...
--Paul Heinlein <heinlein at madboa.com>
More information about the PLUG
mailing list