KBB misc. programs

Dr. K.B.Beard,
Free Electron Laser,
Thomas Jefferson National Accelerator Facility

Muons,Inc.
Lockheed Martin


In memory of my sister, Lisa, 1960-1998


     I flamed amazement: sometime I'ld divide,
                           The Tempest, Act 1, Scene 2


This is a collection of small, very platform independent, general purpose C and Perl programs developed to perform a variety of tasks on UNIX systems. All have the -h (--help) and -V (--version) options. All options must be whitespace seperated; -hV is not equivalent to -h -V. The following are simple examples of how to use these simple programs. .

autoname

return the next filename in the sequence that does not yet exist

$> autoname -f tmp%d.dat +n
tmp0.dat
$> touch `autoname -f tmp%d.dat`;ls
tmp0.dat
$> touch `autoname -f tmp%d.dat`;ls
tmp0.dat    tmp1.dat

beshuffled

rearraign stdin and send it to stdout

$> ls * | beshuffled -P "change #0 to #0.sav"
change L.c to L.c.sav 
change duh.html to duh.html.sav 
change k.C to k.C.sav 
change k.F to k.F.sav 
...


bothstreams

write to both stdout and stderr pipes

$> bothstreams 3 +o
 stdout_0 
 stderr_0  stdout_1 
 stderr_1  stdout_2 


breaktext

insert blank lines into or break text files into multiple files when a value in a column changes

$> cat data.txt | breaktext -b 7 -b 8 # insert a blank line whenever column 7 or 8 changes
1 2 3 4 5 6 7.0 8
1 2 3 4 5 6 7.0 8

1 2 3 4 5 6 7.1 8
...


casa_rm.pl

"remove" files by renaming & moving them to a special directory

$> casa_rm.pl -v -R DIR1
 DIR1/subDIR1/file1 -> /tmp/file1;1034953387
 removing directory "DIR1/subDIR1"
 removing directory "DIR1"


cheapman.pl

creates a simple man page for a program

$> cheapman.pl +d  -sa http://www.jlab.org/~beard/  no_bs 
NO_BS 

 no_bs - manipulates text; removes backspaces and deletes
 -h  --help                  print this help
...
SEE ALSO:

        http://www.jlab.org/~beard/


                                        Tue May 28 17:46:23 2002

count

numbers the lines of a file or stdin

$> count ../SRC/count.c
      1: #include 
      2: #include 
      3: 
      4: #define CoDE "count"    /*name of this program*/
      5: #define this_Version    "v0.1 8/25/1997  K.B.Beard, CSC"
      6: 
...


doh

converts between machine representations of quantities

$> doh -x 4314FF33
 1125449523  10305177463o  4314FF33x   "C..3"   148.996872


duh

converts between even more machine representations of quantities

$> duh -x 4314FF33
 1125449523  10305177463o  4314FF33x   "C..3"   148.997 


facb

masks a number by powers of a base

$> facb 112699
 112699
* 2**0 =  1   
* 2**1 =  2   
* 2**3 =  8   
* 2**4 =  16   
* 2**5 =  32   
* 2**11 =  2048   
* 2**12 =  4096   
* 2**13 =  8192   
* 2**15 =  32768   
* 2**16 =  65536   
 ------------
 112699


genrep2

generates files with repetitive patterns

looks for <n> by default

$> genrep2 -b 2 -e 5 -L "cp x<n>.data x<n>.dat"
cp x2.data x2.dat
cp x3.data x3.dat
cp x4.data x4.dat
cp x5.data x5.dat


html_colors

makes an HTML color table

$> html_colors --black > colors.html


kbb4tape

reads, writes, and copies magnetic tapes

$> kbb4tape -i /dev/rmt/9track6250rew -ri --scan --EUF


krep

searches for multiple patterns in text & binary files

$> krep -p "Dr. K.B.Beard" < ../SRC/krep.c 
 krep -p Dr. K.B.Beard

krep v0.7b  5/29/1999  K.B.Beard


:::::::::::::23=0x17 blocks 515 bytes::::::::::::::::
  /* Dr. K.B.Beard, 4may1998           */
:::::::::::::::::(Dr. K.B.Beard):::::::::::::::::::::::


 1 matches found


kroll

continuously keeps only the last lines of stdin

$> cat ../SRC/* | kroll -v -k 4
kroll: 7477 lines   204273 total bytes

  return(0);

}


mergec

combines C routines and handles headers

$> mergec -v main.c no_newline.c > new.c 
 mergec v0.2b 1/25/1999  Dr. K.B.Beard, CSC

 /* ---------- main.c ------------- */
#include <string.h>
#include <stdio.h>
 /* -


no_bs

manipulates return and linefeed characters, removes or expands overprinting, etc.

$> man csplit| no_bs 



CSPLIT(1)                                               CSPLIT(1)


NAME
       csplit  - split a file into sections determined by context
       lines
...


noop

does nothing but act as a dummy routine; ignores all input and all options except -h and -V

$> noop anything at all


nsmail2msg

unpacks the old Netscape mail "nsmail" directory so that each message appears a its own file named by the time it was sent; provides an easier-to-access all-ASCII archive

$> find nsmail | nsmail2msg -i - -v -p NSMAIL2MSG
 nsmail/6GEV: 
        NSMAIL2MSG/6GEV/7sep2007_13:00:17.msg
        NSMAIL2MSG/6GEV/5oct2007_10:32:03.msg
        NSMAIL2MSG/6GEV/5oct2007_10:32:03.msg
        NSMAIL2MSG/6GEV/5oct2007_10:32:03.msg
        NSMAIL2MSG/6GEV/5oct2007_10:32:32.msg
        NSMAIL2MSG/6GEV/5oct2007_10:32:32.msg
        NSMAIL2MSG/6GEV/5oct2007_10:32:41.msg
        NSMAIL2MSG/6GEV/5oct2007_11:19:20.msg
        NSMAIL2MSG/6GEV/5oct2007_11:29:56.msg
        NSMAIL2MSG/6GEV/5oct2007_11:29:57.msg
        NSMAIL2MSG/6GEV/5oct2007_11:58:09.msg
        NSMAIL2MSG/6GEV/5oct2007_11:58:09.msg
        NSMAIL2MSG/6GEV/5oct2007_12:38:33.msg
 nsmail/6GEV.sbd/HES.HES: 
        NSMAIL2MSG/6GEV.sbd/HES.HES/7sep2007_13:00:33.msg
        NSMAIL2MSG/6GEV.sbd/HES.HES/7sep2007_13:00:38.msg
        NSMAIL2MSG/6GEV.sbd/HES.HES/10sep2007_10:00:33.msg
        NSMAIL2MSG/6GEV.sbd/HES.HES/20sep2007_10:28:55.msg
...


relinker.pl

given an HTML file, goes through and replaces all specified hyperlinks

$> relinker.pl  -r http://wims3 /LOCAL_WWW -o XXX *.html


sdup

duplicate an input stream

$> ps | sdup -t -o ps.log 
Tue May 28 18:07:34 2002:   PID TTY          TIME CMD
Tue May 28 18:07:34 2002:  2145 pts/0    00:00:01 csh
Tue May 28 18:07:34 2002:  2488 pts/0    00:00:00 xload
Tue May 28 18:07:34 2002: 16163 pts/0    00:00:00 ps
Tue May 28 18:07:34 2002: 16164 pts/0    00:00:00 csh


sdup.pl

duplicates a stream

$> sdup.pl --help | sdup.pl -o sdup.pl.txt 
 sdup.pl v0.0 15feb2000, Dr. K.B.Beard, CSC
   -given an input stream or file,
    duplicate stream to stdout and file-

   sdup.pl {options} < input > output
    -h  --help             print this help
    -V  --version          print version an exit
    -v  --verbose          show progress
    -i  --input      FILE  define an input file
    -o  --output     FILE  define an output file
    +H  ++history          record history in output file
    -H  --history          suppress history*

see webpage:
 "http://wims3.larc.nasa.gov/~beard/MISC/"
for more information


sleepy

prints a message at regular intervals

$> sleepy -s 10 -m "waiting" +n -q 3
1 Tue Sep 10 12:13:10 2002 waiting
2 Tue Sep 10 12:13:20 2002 waiting
3 Tue Sep 10 12:13:30 2002 waiting


sork

enhanced numeric sorting

$> sork --example | grep deg | head -4
    deg.1.jpg
    deg.10.jpg
    deg.20.jpg
    deg.5.jpg
$> sork --example | grep deg | head -4 | sork
    deg.1.jpg
    deg.5.jpg
    deg.10.jpg
    deg.20.jpg


testsize

returns the actual byte size and ordering of various C variable types

$> testsize 
 sizeof( char      )= 1 - 67 45 23 01 EF CD AB 89 
 sizeof( short     )= 2 - 4567 0123 CDEF 89AB 
 sizeof( int       )= 4 - 01234567 89ABCDEF 
 sizeof( long      )= 4 - 01234567 89ABCDEF 
 sizeof( long long )= 8 - 89ABCDEF01234567 
 sizeof( unsigned char * )= 4
 sizeof( unsigned int * )= 4
 sizeof( unsigned long * )= 4
 sizeof( unsigned long long * )= 4


today

returns time, converts times

$> today 
today: UTC time=927926301 "Fri May 28 17:18:21 1999" 


unmime_mail.pl

attempt to extract text attachments to an email; removes "+" and "-" from filenames

$> unmime_mail.pl -v -i rms_files.txt
 <-- rms_files.txt 
 44 -->   crest.rms
 877 -->   2deg.rms
 1705 -->   4deg.rms
 2529 -->   6deg.rms
 3357 -->   8deg.rms
 4177 -->   10deg.rms


Several of these routines depend on the KBB C library.

References


K.B.Beard, beard@jlab.org, 29 Jun 2000, updated 18 Oct 2002, 25 Sep 2003, 7 Jul 2005, 10 Aug 2005, 22 Aug 2005, 10 Aug 2007, 17 Oct 2007, 15 Sep 2010, 2 Nov 2012