KitzKikz  KitzKikz: ShellTricks   RecentChanges 
 PopularPages 
 SearchPages 
 Home | Trail - ShellTricks
 
 

These are some unix shell (bash/ksh/tcsh/...) tricks I've collected. I'm placing them here because, typically I'm away from my personal machine when I most need one.


Last Workday/Weekday of the Month (see here)

cal | awk '{print $2,$3,$4,$5,$6}' | tr -s '[:blank:]' '\n' | tail -1


Yesterday in Perl

perl -e '@T=localtime(time-86400);printf("%2d/%2d/%4d\n",$T[4]+1,$T[3],$T[5]+1900)'
perl -e 'use POSIX;print POSIX::strftime("%m/$d/%Y\n",localtime(time-86400))'


Fast Process Search (fps) - I'm constantly checking to see if a certain program or process is running. This helps reduce the typing and the clutter.

    function fps {
        (( $# )) &&
        ps -aux | sed -n "1p;/_µµµµ_µµµµ_fps_µµµµ_µµµµ_/d;/$1/p" ||
        echo "Usage: fps <search string>"
    }


List All Available Man Pages:

man --path | perl -pe 's/:/\n/g' | xargs -J% -n1 find % -type f | xargs basename | sort -u


Dos2Unix Line Ending Conversion:

perl -pi -e 's/\r\n/\n/;' filename ...


Subtract Files: Output all lines in FileA not also in FileB

sort FileA | uniq | sort - FileB FileB | uniq -u
FileAFileBResult
a
a
b
c
d
e
c
d
e
f
g
a
b

If you know that FileA contains unique lines only, then this simplifies to:

sort FileA FileB FileB | uniq -u

 

   

 
 EditThisPage · LinksToPage · PageInfo 01/28/09 13:03:21  ·  0.0777s