Sam Trenholme's webpage
This article was posted to the Usenet group alt.hackers in 1995; any technical information is probably outdated.

Re: A challenge for UNIX wizards


Article: 7887 of alt.hackers
From: and1000@thor.cam.ac.uk (Austin Donnelly)
Newsgroups: alt.hackers
Subject: Re: A challenge for UNIX wizards
Date: 26 May 1995 12:28:19 GMT
Organization: University of Cambridge, England
Lines: 85
Approved: and1000@cam.ac.uk
Message-ID: 3q4hh3$5@lyra.csx.cam.ac.uk
Reply-To: and1000@cam.ac.uk
NNTP-Posting-Host: hammer.thor.cam.ac.uk
Status: RO

In article <D95J9o.HCI@nntpa.cb.att.com>,
C Matthew Curtin <cmcurtin@clipper.cb.att.com> wrote:
>In article <3q185g$3je@lll-winken.llnl.gov>,
>Sam Trenholme <set@oryx.llnl.gov> wrote:
>
>>Ok guys, is there a way of doing this without using a temporary file:
>>
>>ls | awk 'BEGIN{FS="."}{print "mv "$0"
"$1".1"}' > l;chmod 700 l;l;rm l
>>
>>(The above made a list of files, foo.man, bar.man, etc. have the names
>>foo.1, bar.1, etc)
>
>Just to make sure I understand: You want to take a directory full of
>files names something.man and turn them all into something.1, without
>using any temp files? That's easy :-)
>
>ObMiniHack:
>We're assuming ksh (or at least sh) here... Just type this off of the
>command line:
>
>for x in `ls *.man`
>do
>mv $x `ls $x | sed s/\.man/\.1/g`
>done
>

Yup - but your one costs 3N + 1  process invokations for N filenames.
Mine cost N :)

ObHack:
backdrop - a script to change my backdrop automatically.  But, it
picks up the jpegs from another computer since I've got such a tight
quota on my main machine:

---- backdrop -------
set `randline ~/.background_pic_list`
file=$1
shift
opts=$*
if [ -r $file ]; then
  xv -quit -ncols 128 $opts $file
else
  # try & grab it from myrddin
  base=`basename $file`
  rcp myrddin.chu.cam.ac.uk:~/backgrounds/$file
  /home/and1000/pics/myrddin/$base
  if [ -r /home/and1000/pics/myrddin/$base ]; then
    xv -quit -ncols 128 $opts /home/and1000/pics/myrddin/$base
    rm -f /home/and1000/pics/myrddin/*
  else
    xsetroot -solid midnightblue
  fi
fi
------------------------


---- randline ---------
#!/bin/bash
# REQUIRES BASH!

if [ $# != 1 ]; then
  echo <<EOT
Usage: $0 <filename>
	Prints a random line from <filename> to stdout
EOT
  exit 1
fi

filename=$1

set `wc -l $filename`
lines=$1

# Pick one...
line=$[ ( $RANDOM % $lines ) + 1 ]

head -$line $filename | tail -1
--------------------


Austin
_ ___ ________ _   _ ________________________________________________
 / _ \ _  _ __| |_(_)_ _			      Austin Donnelly
|  _  | || (_-<  _| | ' \		     Pembroke College, Cambridge
|_| |_|\_,_/__/\__|_|_||_|			    and1000@cam.ac.uk
---------------------------------------------------------------------



Parent Parent

Back to index