#!/bin/csh
# Script to change the file name in the SQL file to that of the new file name
# To call this script you should type
# ./search_size_csh NEWNAME
# where NEWNAME is the common characters in the file name to search
#
#new filename
set ENTERFILE=$1
if ($ENTERFILE == "") then
   echo "Give the commun characters of the filename to search (USE CAPS):"
   set ENTERFILE = $<
endif
echo "New file name to search $ENTERFILE"
set cw = 0
set s1 = ""
echo "removing size_query.sql"
/bin/rm -f ~/bin/size_query.sql
/bin/rm -f ~/bin/size_query.tmp
cp -f ~/bin/size_query.sql.bkp ~/bin/size_query.sql
set FILELINES=`cat ~/bin/size_query.sql`
echo $FILELINES
#Check each line in the SQL file to change only that with the filename
foreach FILE1 ($FILELINES)
   set t1=`echo $FILE1 | grep %`
   echo $t1
   if ($t1 != "") then
      set FILE1=`echo \"$ENTERFILE%\"`
   endif
   if ($FILE1 == "go") then
     echo $s1 >> size_query.tmp
     echo $FILE1 >> size_query.tmp
     set s1 = ""
   else if ($FILE1 != "go") then
     set s1 = `echo $s1 $FILE1`
   endif
end
/bin/rm size_query.sql
cp size_query.tmp size_query.sql
echo ""
echo "Searching the database"
echo ""
#isql -e -i ./size_query.sql -o size_out.txt -S ZEPPO
isql -e -i ./size_query.sql -S ZEPPO
