Perl script not running from ksh file -


i'm trying run bit of perl inside ksh file , not getting expect it. rather getting sort of error if doing syntactically incorrect, finishes running , creates lots of .bak files has not prepended $data onto every line of file have expected.

what i've got far (contains function declared earlier in file part works fine):

if [[ $# != 3 ]];then      echo "please specify 1 folder containing data files 1 , 1 system id." else     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 worse when run following straight in putty works, appears way i'm trying call perl code (even though i've looked several examples doing similar things) .ksh file:

perl -pi.bak -e 's/^/hi|/' /path/data/file_im_working_with.txt 

if matters, log files not quite doing want. rather making lots of them each sqlldr call overwrites log0.txt every time. i've checked, data files in correct location , may part of problem or unrelated.

thanks in advance!

edit

in addition thissuitisblacknot , dms said, didn't need specify location of perl on system , doing messing up, weird because checked , perl stuff there.

as dms pointed out, echoing perl command, not executing it. also, if want variable data interpolated, need use double quotes, not single quotes. change this:

echo /usr/local/bin/perl -pi.bak -e 's/^/$data/' $filepath 

to this:

/usr/local/bin/perl -pi.bak -e "s/^/$data/" $filepath 

(the echo not necessary run command)


Comments

Popular posts from this blog

css - Which browser returns the correct result for getBoundingClientRect of an SVG element? -

gcc - Calling fftR4() in c from assembly -

Function that returns a formatted array in VBA -