one-liners !!!

contest one liners contest at pride386.PP.COM
Fri Jun 7 08:47:23 AEST 1991


first I wold like to thank all of you who entered this contest!
here are the entrys that passed the tests...and worked
there noa as portable as I would have liked but then some vendors don't
put everything in there packages;-)    

so here they are enjoy, use them but always, don't claim you wrote them 
(unless you did ).

*******************************************************************************
#######                         #
#     #  #    #  ######         #           #    #    #  ######  #####    ####
#     #  ##   #  #              #           #    ##   #  #       #    #  #
#     #  # #  #  #####   #####  #           #    # #  #  #####   #    #   ####
#     #  #  # #  #              #           #    #  # #  #       #####        #
#     #  #   ##  #              #           #    #   ##  #       #   #   #    #
#######  #    #  ######         #######     #    #    #  ######  #    #   ####
*******************************************************************************



From: david at dhw68k.cts.com (David H. Wolfskill)
Well, the only 1-liner I could find that I use is one I call "uulk":

ls -lgt /usr/spool/uucp/LCK*

From: david at dhw68k.cts.com (David H. Wolfskill)
Oops -- I was wrong:  I just found another one ("logins"):

cut -d: -f1 /etc/passwd | sort | pr -8 -t

From: jim at anacom1 (Jim Bacon)

$ for i in `uustat -a | grep mapN | cut -f 1 -d' '`
> {
> uustat -k${i}
> }

This is one line since the shell does not act upon it untill the final
closing brace.  I have shown the prompts as they appear on my screen.

# From: root at ttank.ttank.com (Karl Bunch)

eval `date '+DAY="%d";FF=\`expr %w \* 3 + 23\`' | sed 's/DAY="0/DAY=" /'`;/bin/cal | sed "s/^\(.\{$FF\}\)\($DAY\)/\1`tput smso`\2`tput rmso`/"


[Neat .. on systems that support it. inverse video on the day of the month ]


From: zardoz!share!MBParker

With enough gross csh hacking, MBParkerRmailDates and grepRmail can be 
combined into a one-line csh alias with something like:
alias MBParkerRmailDates "					\
awk '	BEGIN {n= 0; found= 0}					\
	{line[n]= "'$0'"; ++n}					\
	/From: mbparker/ {found= 1}				\
	/"'\037'"/ {if (found) for (l= 0; l<n;++l) {print line[l]}\
		n= 0; found= 0} ' *.rmail 			\
	| grep -i Date:  | awk '{print "'$5, $4, $3, $6, $7'"}'	\
	| sort +0 -1 -n +1 -2 +2 -3 -n +3"
However this alias does not work on all csh implementations and is unmodular
and so is hard to read and difficult to debug.

From: uunet!neuron6.jpl.nasa.gov!harry (Harry Langenbacher)

Ok, here's the best ones out of my .cshrc:

alias dszs 'find . -name "\!{*}*" -ls|sort +6n -7|tail -100|sed -e "s/^[ ]*[1-9][0-9]*[ ]*[0-9]* //" -e "s/^d[-r]........[ ]*/d /" -e "s/^-[-r].\(.\)......[ ]*/\1 /" -e "s/^p[-r]........[ ]*/p /" -e "s/^l[-r]........[ ]*/l /" > /var/tmp/junk.$user.dszs.lis ; ls -l /var/tmp/junk.$user.dszs.lis ; tail -40 /var/tmp/junk.$user.dszs.lis'

which at the prompt would be:

find . -name "*" -ls|sort +6n -7|tail -100|sed -e "s/^[ ]*[1-9][0-9]*[ ]*[0-9]* //" -e "s/^d[-r]........[ ]*/d /" -e "s/^-[-r].\(.\)......[ ]*/\1 /" -e "s/^p[-r]........[ ]*/p /" -e "s/^l[-r]........[ ]*/l /" > /var/tmp/junk.$user.dszs.lis ; ls -l /var/tmp/junk.$user.dszs.lis ; tail -40 /var/tmp/junk.$user.dszs.lis

The above lists all files (not beginning with ".") in &/or under the
current directory, sorts them by sizes, takes the 100 largest, strips down
the "ls" listing to just the more essential information, records the results
in a file unique to the current user-name, and spits out the dope on the
40 biggest disk hogs to the screen.


alias purge 'rm -i \!{*}*.bak \!{*}*.old \!{*}*junk* \!{*}*.~* \!{*}*% \!{*}.*% \!{*}.*.old'

which at the prompt would be:

rm -i *.bak *.old *junk* *.~* *% .*% .*.old

This gets rid of some useless junk in the current directory.

In the alias form of the one-liners, the construct " \!{*}" has the purpose
of allowing another directory than the current one, or to specify some
leading pathname component.

From: root at ttank.ttank.com (Karl Bunch)
SCO Xenix:

cd /usr/spool/lp/request;cd 'cat ../default';ls d0* | sed 's/d0/'`cat
../../default`'/' | xargs cancel

Cancels all pendings requests on the default printer.  We really us
it when a client calls and the stupid printer was off-line..
Meanwhile the users spooled the same job 25 times! so we do:

cd /usr/spool/lp/request/PRINTERNAME
ls d0* | sed 's/d0/PRINTERNAME/' | xargs cancel

most of the time PRINTERNAME is 'printer' under SCO Xenix.

From: root at ttank.ttank.com (Karl Bunch)

uustat -m | sort -r -d +.25

Sorts your UUCP connections by most recent contact.  Great if you
want to know what hosts your host has talked to recently.

From: root at ttank.ttank.com (Karl Bunch)

expr "`echo \`echo '_availmem=X' | adb -p "" /xenix\`"/D" | adb -p '' /dev/kmem`" : '[^	]*\(.*\)'

Prints the number of free pages of memory available under SCO Xenix.

expr `expr "\`echo \\\`echo '_availmem=X' | adb -p "" /xenix\\\`"/D" | adb -p '' /dev/kmem\`" : '[^	]*\(.*\)'` \* 4096

Prints the number of free bytes of memory availble under SCO Xenix.

********************************************************************************
my favorite!
********************************************************************************

From: Raymond Butte <uunet!devnet.la.locus.com!raymond>
A contest?  OK, So here's my entry, a c shell alias:
I have this line aliased to ccg in my .cshrc.

cc -g -o \!^ \!^.c \!:2* >& ,e;grep -v ^$ ,e >,e2;rm ,e; if !(-z ,e2) $EDITOR ,e2 \!^.c

It's used like this:

cshprompt> ccg foo <args>

Where foo.c is a stand-alone C program you wish to compile.
Here's what it does:
-tries to compile the foo.c, with optional command line flags for
the linker, putting object file in foo.
-std error goes into a file called ,e
-,e is relieved of any empty lines, and results end up in ,e2 
-,e is removed
-if there is still output in ,e2 it means your compiler/linker has written
something to stderr, usually errors, although some compilers write silly
copyright notices to standard error. (if your compiler has that dumb behavior 
it will have to be turned off for this script/line to work perfectly).
The script checks for any such error output, and if it exists, calls the
program you have defined in your environment as your $EDITOR, and puts you in
that program editing the error file, with the original .c file as your 
secondary file to edit.  If you use vi, you can then flip back and forth 
between the error file and source code with either \036 [Ctrl-^] or :e #
You can similarly leave out the -g and call your alias CC, or mycc.

[ note.- once in vi type :n then you can flip using [Ctrl ^]  or :e # ]


From: uunet!auspex!ams (Allan Schwartz)


#       411 -- cshell script to give "directory assistance"
fgrep -i $* ~/lib/phonebook | awk -F: '{print $1 "\t" $2}'

#       cfmt -- filter a c-style comment block throught the fmt filter 
sed 's/^ \*//' | fmt | sed 's/^/ */'

#       closeall -- close all shelltools and cmdtools on an unsuspecting user
ps a | awk '$2 ~ /^p[0-9]*$/ && $5 ~ /shelltool|cmdtool/ {printf "\033[2t" >"/dev/tty"$2}'

#       colm -- place text (such as /etc/fstab) in columns, ignoring comments
sed -e '/^[^#]/s,[ 	][ 	]*,	,g' | expand -${1-"10,22,30,39,90"} | unexpand

#       force_cmd -- use the "send_line" feature of the Televideo terminal
#		to have some other logged-in user execute a command
echo -n "" $1 "\0336" "\033T" > /dev/tty$2

#       illegal -- leave a notice that SCCS/RCS was circumvented
echo "caution: illegal copy of $1, (made by `whoami`, `date`)" > $1.ILLEGAL; chmod 666 $1

#       lu -- "look-up" a word in the dictionary
egrep $1 /usr/dict/words

#       mailbars -- filter to reformat text on the left half of the page
#		... so a response can added to the right half
fmt -38 | awk '{printf("%-39s| \n",$0)}'

#	pr1page -- print 1 page of an nroff output file
echo $1 $2 | awk '{printf("sed -n %d,%dp %s\n", ($2-1)*66+1, $2*66, $1)}' | sh

#       reverse_cat -- display a file backwords
grep -n "^" $* | sort -rn -t: | cut -d: -f2-

#       rot13 -- filter to translate a dirty joke
tr "[a-m][n-z][A-M][N-Z]" "[n-z][a-m][N-Z][A-M]"

#       scroll -- emit 24 linefeeds 
# 		... done before a vi, so RedRyder will save the screen
echo | awk 'END{printf("\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n")}'

#       set_kernel_word -- shell script to set a kernel variable
#		... without this script, I can never remember the correct syntax
echo "$1/w $2" | adb -k -w /vmunix /dev/mem

#       sum_column -- awk script to sum up the last column of stdin
#		... especially good at adding quick phone bills, invoices, etc.
awk '/[0-9.]*$/{ sum += $NF }{ print $0 } END{ printf "\t\t\t-------\n\t\t\t%7.2f\n", sum }' -

#       sum_du -- awk script to sum up the first column of stdin
awk '{ sum += $1; print } END { print "-------\n" sum "\ttotal }' -

#	textfiles -- decide which files are "text" files
file $* | egrep "text|script" | awk -F: '{print $1}'

#       unln_cp -- shell script to change ownership in a writable directory
mv $1 tmp$$ ; cp tmp$$ $1 ; rm tmp$$

#       writable -- script to find the edited files in a development directory
find . -perm -200 -type f ! \( -o -name '*.o' -o -name tags -o -name .make.state \) -print | xargs ls -ld

From: Peter da Silva <uunet!ficc.ferranti.com!peter>

ls -alR ${1+"$@"} | awk '{if (NF==9) h($3) += $5} END {for(i in h) print i,h(i)}'

List disk usage by user in the named directories.

[this is the portable version ... orignal had "hog" insted of "h" ]


From: Wes Morgan <uunet!ukma!morgan>
ls -l | awk '/^d/ { print }'

From: zardoz!conexch!root

This one reports the number of bytes used in the default dirctrory tree:
expr `du -s | cut -f1` \* 512

This one list files 6 across:
ls -p $* | pr -6 -t -w80


From: uunet!NCoast.ORG!allbery (Brandon S. Allbery KB8JRR/AA)

ls|sed -e h -e 'y/ABCDEFGHIJKLMNOPQRSTUVWXYZ/abcdefghijklmnopqrstuvwxyz/' -e 's/.*/mv \& /' -e G|sh -x

This renames files off a DOS floppy to lowercase.  And yes, I *have* typed
this on the shell command line!  This can also be used to rename files with
common changes by replacing the y/// with something else, e.g. "s/foo/bar/" to
rename all *foo* to *bar*.  (If you do this, use e.g. "ls *foo*" or you may
get a lot of error messages on filenames that *don't* contain "foo".)

--------------------------------------------------------------------------
hope you liked them!
prizes were:
msdos 'C' compiler  	---  Karl Bunch
font cartrage (donated by Anacom General)      ---	David Wolfskill
Dragon Star T-shirts		               ---	Karl Bunch
                                                        David Wolfskill
                                                        Jim Bacon
			                                
Esix Tshirts  every one else!

P.S.  Believe it or not ..... Cray called me this morning (better late than never) 
" The "Crays" are on there way ..." ????
I checked the man out and he is who he says he is .........
[was going to ship the tshirt out today ... but will wait for the "crays"
 so if you didn't get you tshirt hold on a couple ...]
Terry




More information about the Comp.unix.programmer mailing list