Slashdot Mirror


User: ramune

ramune's activity in the archive.

Stories
0
Comments
1
First seen
Last seen
Profile
(view on slashdot.org)

Comments · 1

  1. portable commands on (Useful) Stupid Unix Tricks? · · Score: 1

    While some people like grep -r, xargs -0, etc. -- I deal with many UNIX variants, so I need a portable subset. Hence:

    # Daemonize a process
    nohup sh -c 'command > /dev/null 2>&1 </dev/null & ' > /dev/null 2>&1 </dev/null &
    # Convert a file to LF from CR/LF
    tr -d '\015' < foo.txt > bar.txt
    # Scripted editing of a file when you don't need something as complex as awk/sed
    # (or they have odd problems/limitations on that platform):
    $ ed foo.c <<__EOL__
    1 /stdio.H
    s/stdio.H/stdio.h/
    w
    q
    __EOL__

    # Recall history and edit it as a text file, then run it in the shell.
    # Defaults to /bin/ed on many Bourne-shell variants unless you set FCEDIT.
    # Useful to repeat a long sequence of actions taken while you were trying to
    # figure out how to do stuff.
    FCEDIT=${VISUAL:-/usr/bin/vi} export FCEDIT
    fc

    # Useful for annotating stuff when commenting on a file -- numbers them:
    nl file.txt
    # Easy way to check for a byte occuring in a file -- handy in certain types
    # of input validation and forensics.
    od -t x1 file.txt | grep 'a9'
    # And something Debian/bash-specific. You figure it out. :-)
    MAX_NR=0 ; varry=(`deborphan -an|awk '{print $2}'|sort|tr '\012' ' '`) ; i=${#varry[@]}; while [ $i -gt 0 ] ; do NR=`echo ${varry[$((i-1))]}|wc -c` ; if [ $NR -gt $MAX_NR ] ; then MAX_NR=$NR ; fi ; i=$(($i-1)) ; done ; NR_PER_LINE=$(( $((COLUMNS-1)) / MAX_NR )) ; FSTR="%${MAX_NR}s|" ; while [ $i -lt ${#varry[@]} ] ; do CURCOUNT=0 ; echo -n '|' ; while [ $CURCOUNT -lt $NR_PER_LINE ] ; do printf "${FSTR}" ${varry[$i]} ; i=$(($i+1)) ; CURCOUNT=$(($CURCOUNT+1)) ; done ; echo ; done|less