[techtalk] help with sorting text in a file
Jeff Dike
jdike at karaya.com
Fri May 12 12:27:29 EST 2000
slandrum at turing.csc.smith.edu said:
> On Fri, 12 May 2000, alissa bader wrote:
> > Specifically, anything containing the
> > string "QAA." Tried doing a grep, but I got the
> > entire line again, not just the portion of it that
> > contained "QAA."
> what part of the line do you need to grab, other than QAA? got some
> sample data?
You wouldn't be grepping a mail log would you?
slandrum is right - you've told us not very much. I'll assume that the QAA is
part of a field, like this, except I've got LAA instead:
May 12 11:39:45 ccure sendmail[2245]: LAA02244: to=<jdike at localhost>,
delay=00:00:01, xdelay=00:00:00, mailer=local, stat=Sent
Here, the LAA is in field 6 (starting from 1), so awk would be a good choice.
If you just want that field, and you want it sorted by the rest of that field
for some reason, you could do this:
cat /var/log/maillog | \
awk '{print $6}' | \ # The *AA fields come out here
grep LAA | \ # Only the LAA field survive this
sed 's/LAA//' | \ # Strip the LAA off, leaving the number
sort -n # Sort them
If you wanted other parts of the line, the awk command could be something like
awk '{print $6, $7, $1, $2, $3}'
which would give you "LAA02244: to=<jdike at localhost> May 12 11:39:45". This
would let you select or sort by date and username.
If all of this is barking up the wrong tree, then you'll have to be somewhat
more specific.
Jeff
More information about the Techtalk
mailing list