#!/bin/csh -f
# addinventory-level0

# Adds new entry to level 0 inventory file.

# February 23, 1999.  Change update message to reflect master file.  rcg
# R. Groman February 20, 1997
cd /data/rgroman/Inventory/scripts

set backup=/data/rgroman/Inventory/backup

set datadir=/data/rgroman/Inventory
#set datadir=/data/rgroman/Inventory/debug

#Make backup of existing data file just in case
setenv TMP `date '+%Y.%b.%d.%H%M'`
cp $datadir/toplevel.dat $backup/toplevel.dat-$TMP

if ( -e /tmp/toplevel.dat ) \rm -f /tmp/toplevel.dat
cp $datadir/toplevel.dat /tmp/toplevel.dat

#Save comments
if ( -e /tmp/comments ) \rm -f /tmp/comments
head -3 /tmp/toplevel.dat > /tmp/comments

#Add current date to comments
echo "# Master list last updated: $TMP" >> /tmp/comments

#Save existing data with and without field names
if ( -e /tmp/data ) \rm -f /tmp/data
tail +5 /tmp/toplevel.dat > /tmp/data
if ( -e /tmp/data1 ) \rm -f /tmp/data1
tail +4 /tmp/data > /tmp/data1

#Save field name lines
if (-e /tmp/fieldnames ) \rm -f /tmp/fieldnames
head -3 /tmp/data > /tmp/fieldnames



#Add new record (must replace spaces with tabs first) and sort
cat inventoryopt  | tr '\040' '\011' >>/tmp/data1

\rm -f /tmp/data
sort /tmp/data1 > /tmp/data

#Recombine sorted file with comments
cat /tmp/comments /tmp/fieldnames /tmp/data >$datadir/toplevel.dat

