[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[ale] cut



Okay, in keeping with the TIMTOWTDI philosofy, I decided to contribute this:

history | tr -s ' ' | cut -f3 -d ' ' | uniq -c | tr -s ' ' | cut -f2 -d ' '
| sort -nr | head

It resolves your spacing problem by using the command "tr" that squeezes
spaces (or whatever character you "-s"pecify.) into a single character.
It's quite useful:
tr -s " " = truncate x spaces into " " (a single space)

It's great for working with fields and it complements `cut` quite nicely.

just my .02 pfenning,
CB



> -----Original Message-----
> From: Greg Sabino Mullane [mailto:greg at turnstep.com]
> Sent: Saturday, March 09, 2002 12:48 PM
> To: ale at ale.org
> Subject: Re: [ale] cut
>
>
>
> -----BEGIN PGP SIGNED MESSAGE-----
> Hash: SHA1
>
>
> > ...The idea is to tell you which commands appear most in your
> > history and by how much.
> > ...
> > I've tried cut -d' ' -f1, but it doesn't work for some reason.
>
> Cut only works on fixed field data, which history does not produce. The
> history output is separated by one *or more* spaces, and is more
> concerned
> with looking pretty by right-aligning the numbers and left-aligning the
> commands.
>
> As mentioned, the awk program is an excellent choice for this:
>
> > history 1000 | awk '{print $2}' | sort | uniq -c | sort -nr | head
>
> I like the above: it is probably the best way to do it. However, in the
> spirit of TIMTOWDI, here's a perl solution that goes about it a bit
> differently. Note the use of $HISTFILE, a handy shell variable to know.
> You might want to play around with $HISTSIZE to generate larger sample
> sizes for your command frequency analysis. This is wrapped for email,
> but should be entered all on one line:
>
> perl -ne '$C{$1}++ if /(\S+)/; END {for (sort
> {$C{$b} <=> $C{$a}} keys %C) { print "$C{$_} $_\n";} }' $HISTFILE | more
>
> Ain't perl beautiful? :) Note also that the $HISTFILE does not contain
> the numbers, so we don't need to worry about offsetting into a field.
> Just for the record, here are my top five:
>
> 1037 fg
> 489 perl
> 322 cd
> 305 edit
> 200 l
>
> (edit is an alias for emacs, and l is an alias for 'ls -lart')
>
> Bored on a Saturday,
> Greg Sabino Mullane greg at turnstep.com
> PGP Key: 0x14964AC8 200203091242
>
> -----BEGIN PGP SIGNATURE-----
> Comment: http://www.turnstep.com/pgp.html
>
> iD8DBQE8ikqdvJuQZxSWSsgRAvmCAKDl+TbnbYbC2PQj22ncSu7cCm/zsQCgyPVY
> 1Ujm3LyUe438XwCIHXkX9iI=
> =7cfz
> -----END PGP SIGNATURE-----
>
>
>
> ---
> This message has been sent through the ALE general discussion list.
> See http://www.ale.org/mailing-lists.shtml for more info.
> Problems should be
> sent to listmaster at ale dot org.
>


---
This message has been sent through the ALE general discussion list.
See http://www.ale.org/mailing-lists.shtml for more info. Problems should be 
sent to listmaster at ale dot org.