HGS Goodies

sorting  sort  LaTeX  Backup










smart copies  awk  Scanning  FrameMaker










 hash   variables  assignment   sed  Convert
MS-Word
 csh tricks










 find  symbolic  links  ps to pdf  fonts on HP-UX (gere) 










 fonts for line-draw (gere)  color  ps to pixel grapics GETARG and GETENV work-around
(mostly for Cygwin)











 emacs customize














 Good procedures

sort:

sort -k 5n

use field 5 (numeric) in a blank-separated set of columns


Smart copies

(cat temp.lst | xargs -i find . -name {}) | xargs -i cp -i {} ~/tmp/Olmpp/p
where temp.lst is a list of file names, short form (no path). The command line above finds the path/file.name of each file and collects copies of these files in the destination directory ~/tmp/Olmpp/p
The list above has been created using
fcm olmpp map
fgrep Selecting olmpp.map > tmp.lst
Editing, change *.o to *.f:
cut -d " " -f 4 tmp.lst | sort | uniq | sed 's/.o$/.f/' > temp.lst
An alternative is
mneeds short `ldneeds` > temp.lst
emacs temp.lst
cp `awk '{printf "%s ",$1}' temp.lst` directory
See also shell script hgs/bin/mneeds
 

Another smart copy:

Imagine you have changed files in a mirrored disk area, but the mirror has not worked for 29 days.
The mirror directory was /hgs, the original, termporarily disabled directory was /Bifrost/hgs
find . -type f | Filetime -n - | awk -F\t '\!/No such file/{if($2<30){gsub(/ /,"",$1);
sub(/.\//,"",$1); printf "cp ./%s /Bifrost/hgs/%s\n",$1,$1}}' > cp.bat

source cp.bat

Filetime is a perl procedure (linked to /home/hgs/perlproc/Filetime.pl)
The awk that filters out the lines with "No such file" is needed, since we might have unresolvable links.
The line could be simplified to
find . -type f | Filetime -n - | awk -F\t -v d=/Bifrost/hgs/ -f ft2cp.awk > cp.bat
using a file ft2cp.awk
\!/No such file/
{if($2<30){gsub(/ /,"",$1);
           sub(/.\//,"",$1);
           printf "cp ./%s %s/%s\n",$1,d,$1}}


Backup only files changed since xx days

We have a nice little perl script ~/bin/Filetime

     find . -type f | fgrep -v ETERNA34 | fgrep -v .netscape/cache |\
       Filetime -f -M 31 - > ! BU_020912/upd_since_020813.lst

will make a list of files in the directory tree younger than 31 days

To do the actual copy,

     tar cfv BU_020912/BU_020912.tar `cat BU_020912/upd_since_020813.lst`

Now, this tar can be copied e.g. to CD-R



Hash-variable assignment in sh
In this example the strings that are copied from the first line of file $file may contain
backslash and parenthesis. sed and awk were difficult to use
for i in $*
do
eval u\=\'`head -1 $file | awk -v c=$i -f pac.awk `\'
eval site_$i\=\$u
eval echo site$i: \$site_$i
done

eval site\=\$site_1
echo $x $y 12 0 0 5 $site | pstext ...

will work



Find

See the manual page.

find . -type d -name "[A-z]*" | sort -r | xargs rmdir -f
removes all subdirectories below.
 
find . -type f | xargs rm -f
removes all files below.
 
find . -type f -acl '=*.*+x'
finds all files with the execution bit set for everyone.
 
find . -type f -acl '*.*+x'
finds all files with the execution bit set for someone.
 

      find . -type f -follow -acl '*.*+x' -exec ll {} \; | awk '{if ($5 < 25000) print $9}'

finds practically all shell scripts.

      find . -type f -hidden | xargs ls -la | awk '{if ($5 > 500000) print $0}'

prints all files larger than 500 kbytes down the dir tree
 

Find a module, search all libraries:
Example: find alpfn.o
      find . -name 'lib*.a' -exec myar {} \; |\
      fgrep -e "alpfn" -e 'LIB'
with ~/bin/myar as follows
      #!/bin/sh
      echo "\nLIBRARY $*"
      ar $*

The command list above is available as a shell script:

      ~hgs/bin/search-ar name


Fonts:
  line draw

      -fn spc08x14h

is an X-window toolkit option that many programs understand. Inside some programs you have to switch to alternate character sets, like in

emacs:
         M-x standard-display-european

nedit:
      (menu) preferences -> Text Font -> Font Name -> spc08x14h

      nedit -geometry 760x480 -fn spc08x14h !* >& /dev/null &
 


Sort:

       ls -l | sort -k 5n -r

sorts file list by size, largest last (key is column 5)



awk:

    awk '{for ( i=3 ; i<=NF ; i++ ) printf "%s ",$i; printf "\n"}'

is a simple loop to print input fields number 3 and beyond.

    awk '{if ($1 > 1980 ){printf(" %7.3f %7.3f\n",$1,$2)}}' furratpg.dat

prints those records which are from 1980 and later, columns 1 and 2 of 1,2,3 More awk's
in ~/clim/p/pgwl_plot,  ~/bin/*.awk


sed:

    dp=`echo $out | sed "s@$i1\(.*\)$i2.stacov\(.*\)@\1@"`

extracts the date part from a stacov file name

Case and character conversion:

     echo "beba" | sed 'y/abcde/ABCDE/'
     BEBA

     foreach file ( euro*.txt )
     mv $file `echo $file | sed "s/\(.*\)\.\(.*\)/\1.95.\2/"`
     end
renames euroXX.txt  to  euroXX.95.txt

     fgrep Selecting Oload/p/mpp/olmpp.map | awk '{print $2}' |\
     sed 's/\(.*\).o/\1.f/' | xargs -i find . -name `echo {}`

goes thru a link-map, looks at the symbols and tries to find the associated source files in the directory tree

     ls -l | awk -v PWD=$PWD \
             'BEGIN{print "cd " PWD} {if ( index($1,"lr") == 1 ) print "ln -s", $11, $9}' \
                    > ~/div/`echo $PWD | sed 's:/:_:g'`.

links generates commands useful to re-establish linked file structures. The output is saved in a file ~/div/${MPWD}.links where MPWD is PWD with the /-signs replaced by _



symbolic links:

     cd ~
     ls -lR | awk '{ if ( NF == "1" ){CDR=$1} else                  \
                    { if ( NF == "11") {print "cd", CDR;            \
                                        print "ln -s",$11,$9        \
                                       }                            \
                    }                                               \
                   }' | sed 's/\(.*\):/\1/' > ~/div/all-links.lst
or
     ldl

is a short special ls-type command for listing the links in the directorie(s) / file name(s) given by the arguments. The result shows the path/name of the file and the name of the link. With ldl one can copy links rather than files.

Example: copy the links that exist in directory ../A to the current directory
     ldl ../A | xargs -n2 ln -s

--
     ls -lR | awk '{if ( NF == "1" ){print "DIRECTORY::" $0}  \
                    else            {print $9,$10,$11} }'     |\
               fgrep -e '::' -e '->'

finds all symbolic links below the current directory.

     ls -lR | awk '{if ( NF == "1" ){CDR=$1} \
                    else            {print "In",CDR,"linked",$9,$10,$11} }' |\
               fgrep -e '->'

this version does not print the searched-thru dirs.

Have a look at ~hgs/bin/lsl
     lsl -h



To replace a color in Image-Magick display to transparent, use Matte function. You probably need to set
up a private color map.

    xstdcmap -best
    display -map best file



LaTeX

Posters:
We made one Nov 1999: ~/TeX/AGU-FM99/bifrost.*

The poster is produced in A3 format originally. Use

   dvips -O0.0cm,3.5cm -t a3 -o bifrost.ps bifrost
 

To analyze a text for correctly paired braces, use

   ~hgs/bin/atext file
   $

To analyze a text for correctly paired Dollar signs, use

   ~hgs/bin/dollar-pairs file
   $

The source code in each case is found in ~hgs/util/p/m


Successful compilation of curses library:

    cc -Ae -Dhpux -I/usr/local/elm-2.4.24/hdrs -c curses.c


eval in csh:

In the csh, the existence of composed variables is difficult to test. Here's a solution:

    eval set aliasd\=\$\{\?${1}_alias\}
    if ( $aliasd == 1 ) then
       eval set alias\=\$$1_alias || echo bad but good
    else
       set alias=" "
    endif
    echo 'Alias site name is ->'${alias}'<-'

Now, if you
    setenv WETB_alias WTZR
and call a procedure (proc) containing the code above
    proc WETB
the variable $alias will carry WTZR; but if you call it by
    proc ONSA
the variable $alias  will carry one blank.


Scanning:

   xhost +
   telnet beisla
   user: xvscan
   password: sjIIcx
   setenv DISPLAY mystation:0.0
   cd hgs
   xvscan
-> windows -> scanner (^a)

Use the following settings to get white page background and reasonable contrast:
contrast +85 or greater
brightness +40 or less
resolution 300 dpi
First quick scan, then (hi-q) scan. Don't use hi-q scan two times in a row. With greater resolution than 300 dpi the program drops dead. Use tif as the saving format. jpg has been observed to suffer from dropouts.


Convert MS-Word doc files:


   cd ~/wv
   wvHTML file.doc > file.html

(installation has problems with image files and euro-characters).


Convert ps to pdf


We have FrameMaker and Distiller under it. Therefore
add  /Frame/bin  to  PATH  and

    setenv FMHOME=/Frame
    distill file.ps


FrameMaker

FrameMaker will create temporary files under $HOME ( $HOME/.fm*.*/ )
In order to prevent the /home disk to be completely swamped, start the program with

   mkdir /temp/$USER # once for all
  ( setenv HOME /temp/$USER; maker )
 

Setting the standard printer for use in batch printing:

   mkdir ~/fminit

create file FMprinterlist containing
   #!/bin/sh
   cp /home/$USER/fminit/myfmprinterlist $1

and don't forget
   chmod u+x /home/$USER/fminit/FMprinterlist

Create file /home/$USER/fminit/myfmprinterlist containing
   pslaser_1

or whatever your favourite printer is called. Next time you can print your document as a batch process:

   fmprint document.fm

(the -p option did not work last time I tried)


PostScript conversion to pixel-based graphics

(1) Conversion with Ghostscript

cat file.ps | gs -q -sDEVICE=jpeg -sOutputFile=file.jpg -
Better quality: use png  This format can also be displayed in netscape etc.
cat file.ps | gs -q -sDEVICE=png256 -sOutputFile=file.png -
cat file.ps | gs -q -sDEVICE=png16m -sOutputFile=file.png -
cat file.ps | gs -q -sDEVICE=png16m -sOutputFile=file.png -r300 -
( -r300 to get 300dpi, not the default 72dpi)

(2) Conversion with ImageMagick's convert

convert -quality 75 -density 300dpi file.ps file.jpg


 

(t)csh tricks

(1) interactive execution

As I haven't been able to dig up a read command in csh/tcsh, the following was found to work
foreach s ( `cat list.txt` )
echo Do section $s '? '"\c"
set ans=`sh ' read XXX ; echo $XXX ' | tr '[A-Z]' '[a-z]'`
if ( x`beak $ans` == xy ) then
   echo o.k., lets do $s
endif
end
It has some nice features. For instance, the carriage-return is suppressed. The response is translated to lower-case.
Uups, what's the beak command ? Very simple: retain the first character of a string by
echo "$1" | sed 's/\(.\).*/\1/'
that's the only line in that shell script (it works in all shells).


Screen Fonts on HP-UX (gere)

See the fonts in
/usr/lib/X11/fonts/misc/fonts.alias
/usr/lib/X11/fonts/misc/fonts.dir
and other directories - search for fonts.dir and fonts.alias
find /usr/lib/X11 -name fonts.dir
The font can be displayed using the long names, e.g.
xfd -fn '-adobe-courier-medium-r-normal--8-80-75-75-m-50-hp-roman8'
and they can be used in applications, e.g.
emacs -fn '-adobe-courier-medium-r-normal--8-80-75-75-m-50-hp-roman8'
The first column in the fonts.dir files hint at short names, e.g.
courR08.pcf.Z -adobe-courier-medium-r-normal--8-80-75-75-m-50-iso8859-1
emacs -fn courR08



Emacs customize:

Set your TAB behaviour in Perl
Using the interactive capability in the command window:
^M-x customize ->Programming -> Languages -> Perl


.bye