I need to search through a directory, ARCHIVE, which contains many sub directories, each which contain files. Each file has an email address in it. I want to list all of the email address’, with the @blah.com truncated, then list the occurrences for each name.
I figured out how to find the emails and truncate the @ part, but I can’t figure out how to count how many times each individual name occurs.
grep -R '^To: ' $ARCHIVE | cut -d@ -f1 | awk '{print $2}' | sort | uniq
Also for some reason I can’t get this to work in a script; whenever I call it it does nothing, but if I put it in the command line it works.
So with our long comment conversation I would do this:
This will take the output of the
uniqcommand, write it to a file and then gather a total and append it to the same file for you to see at the bottom.Or as Geoff pointed out you could do
uniq -c file.txt | awk '{print}END{print NR}'.