I'm trying to run a bit of perl inside a ksh file and not getting what I would expect from it. Rather than simply getting some sort of error if I was doing something syntactically incorrect, it finishes running and creates lots of .bak
files but has not prepended $data
onto every line of the file as I would have expected.
What I've got so far (contains
is a function I declared earlier in the file but that part works fine):
if [[ $# != 3 ]];then
echo "Please specify 1 folder containing data files as well as 1 from and 1 to system id."
else
for file in `ls $1`;do
filePath=$1$file
fileName=`echo $filePath | awk -F'/' '{print$5}'`
contains $fileName "ACCUMS" && (
contains $fileName ".bak" || (
echo "Loading file: "$fileName
date=echo $fileName | awk -F'_' '{print$5}' | sed 's/.txt//'
data=$fileName"|"$2"|"$3"|"$date"|"
echo $data
echo /usr/local/bin/perl -pi.bak -e 's/^/$data/' $filePath
logFile="log"$curFile".txt"
echo "Log file: "$logFile
echo "Done loading file: "$fileName
$ORACLE_BIN/sqlldr user/pass@server control=control_file.ctl data=$filePath log=$logFile
curFile=$curFile+1
)
) || echo $fileName" not part of Accums. Skipped."
done
fi
To make it worse when I run the following straight up in PuTTY it works, so it appears to be the way that I'm trying to call the perl code (even though I've looked a several examples doing similar things) from the .ksh
file:
perl -pi.bak -e 's/^/hi|/' /path/data/file_Im_working_with.txt
If it matters, the log files are also not quite doing what I want. Rather than making lots of them for each sqlldr call it just overwrites log0.txt
every time. I've checked, the data files are in the correct location and everything so this may be part of my problem or something completely unrelated.
Thanks in advance!
EDIT
In addition to what ThisSuitIsBlackNot and dms said, I also didn't need to specify the location of perl on this system and doing so was actually messing it up, which is weird because I checked and perl stuff was there.