Help with String concatenation

I have a script which is migrated from AIX to Linux & now while running it is no able to concatenate string values
The string concatenation step under while loop is not displaying desired result
Please find below the piece of code:

while read EXT_FILE ; do
EXT_FILE=$EXT_FILE.ext.sent
echo "Extract file $EXT_FILE validated." >> $LOG_FILE
if [ -f $EXT_FILE ]
then
echo "Deleting file $EXT_FILE." >> $LOG_FILE
rm $EXT_FILE
# echo "SQL Command: EXECUTE x0uaroperator.purge_valid('$EXT_FILE')" >> $LOG_FILE
sqlplus $ORAUSER/$ORAPWD@$DATABASE << SQLEOF >> $LOG_FILE
EXECUTE x0uaroperator.purge_valid('$EXT_FILE');
EXIT SQL.SQLCODE;
SQLEOF
EXIT_STAT=$?
echo "Validated $EXT_FILE SQL Exit Code: " $EXIT_STAT >> $LOG_FILE
else
echo "Extract file $EXT_FILE not found." >> $LOG_FILE
fi
done < $WORK

The echo displays following line .ext.sent validated.6
The desired echo output is Extract file 9000008 validated
It is unable to suffix .ext.sent to the EXT_FILE(value of EXT_FILE is 9000008 and it comes from a list)

Please suggest how to suffix .ext.sent to the EXT_FILE

Thanks,
Preeti

which linux are you using? try any of the below

 
EXT_FILE=${EXT_FILE}.ext.sent
EXT_FILE=${EXT_FILE}".ext.sent"
EXT_FILE=$EXT_FILE".ext.sent"

It is GNU/Unix

I tried all of the above syntax. Still not working

Thanks,
Preeti

can you run your script as sh -x script name? post the output

Please find the output below:

 
-sh-4.1$ sh -x ext_valid_new.S ausa
+ export ORACLE_BASE=/opt/oracle
+ ORACLE_BASE=/opt/oracle
+ export ORACLE_OWNER=oracle
+ ORACLE_OWNER=oracle
+ export HOME=/purge
+ HOME=/purge
+ export ORACLE_HOME=/opt/oracle/product/11.2.0.3/dbhome_1
+ ORACLE_HOME=/opt/oracle/product/11.2.0.3/dbhome_1
+ export ORACLE_SID=uad1
+ ORACLE_SID=uad1
+ export TMP=/tmp
+ TMP=/tmp
+ export TMPDIR=/tmp
+ TMPDIR=/tmp
+ export TNS_ADMIN=/opt/oracle/product/11.2.0.3/dbhome_1/network/admin
+ TNS_ADMIN=/opt/oracle/product/11.2.0.3/dbhome_1/network/admin
+ export ORACLE_ADMIN=/opt/oracle/admin
+ ORACLE_ADMIN=/opt/oracle/admin
+ export LIBPATH=/opt/oracle/product/11.2.0.3/dbhome_1/lib:/opt/oracle/product/11.2.0.3/dbhome_1/n          etwork/lib
+ LIBPATH=/opt/oracle/product/11.2.0.3/dbhome_1/lib:/opt/oracle/product/11.2.0.3/dbhome_1/network/          lib
+ export NLS_LANGUAGE=AMERICAN_AMERICA.WE8ISO8859P1
+ NLS_LANGUAGE=AMERICAN_AMERICA.WE8ISO8859P1
+ export NLS_LANG=AMERICAN_AMERICA.WE8ISO8859P1
+ NLS_LANG=AMERICAN_AMERICA.WE8ISO8859P1
+ export LD_LIBRARY_PATH=/opt/CA/SharedComponents/lib:/opt/oracle/product/11.2.0.3/dbhome_1/lib:/u          sr/lib
+ LD_LIBRARY_PATH=/opt/CA/SharedComponents/lib:/opt/oracle/product/11.2.0.3/dbhome_1/lib:/usr/lib
+ export LIBPATH=/opt/oracle/product/11.2.0.3/dbhome_1/lib:/opt/oracle/product/11.2.0.3/dbhome_1/n          etwork/lib:/opt/oracle/product/11.2.0.3/dbhome_1/lib
+ LIBPATH=/opt/oracle/product/11.2.0.3/dbhome_1/lib:/opt/oracle/product/11.2.0.3/dbhome_1/network/          lib:/opt/oracle/product/11.2.0.3/dbhome_1/lib
+ export ADMIN_HOME=/opt/oracle/admin
+ ADMIN_HOME=/opt/oracle/admin
+ export AGENT_HOME=/opt/oracle/product/agent11g
+ AGENT_HOME=/opt/oracle/product/agent11g
+ export SCRIPT_DIR=/opt/oracle/admin/scripts
+ SCRIPT_DIR=/opt/oracle/admin/scripts
+ export BS_DIR=/opt/oracle/admin/backup
+ BS_DIR=/opt/oracle/admin/backup
+ export LOG_DIR=/opt/oracle/admin/logs
+ LOG_DIR=/opt/oracle/admin/logs
+ export ORATAB=/etc/oratab
+ ORATAB=/etc/oratab
+ export PATH=/usr/bin:/etc:/usr/sbin:/usr/local/bin:/usr/local/bin/nmon:/purge:/purge/bin:/opt/or          acle/product/11.2.0.3/dbhome_1/bin:/usr/ucb:/usr/bin/X11:/sbin:/usr/lib64/qt-3.3/bin:/usr/local/bi          n:/bin:/usr/bin:/usr/local/sbin:/usr/sbin:/sbin:/opt/oracle/product/11.2.0.3/dbhome_1/bin:.
+ PATH=/usr/bin:/etc:/usr/sbin:/usr/local/bin:/usr/local/bin/nmon:/purge:/purge/bin:/opt/oracle/pr          oduct/11.2.0.3/dbhome_1/bin:/usr/ucb:/usr/bin/X11:/sbin:/usr/lib64/qt-3.3/bin:/usr/local/bin:/bin:          /usr/bin:/usr/local/sbin:/usr/sbin:/sbin:/opt/oracle/product/11.2.0.3/dbhome_1/bin:.
+ OPCO=ausa
+ LOG_FILE=/purge/ausa/logs/ext_valid.log
+ EXT_PATH=/purge/ausa/extracts
+ MF_FILE=extvalid.lst
+ BACK1=extvalid.bk1
+ BACK2=extvalid.bk2
+ BACK3=extvalid.bk3
+ WORK=extvalid.wrk
+ ORAUSER=s0uaroperator
+ ORAPWD=s0uaroperator
+ echo ' '
++ date
+ echo 'Starting Purge/Extract FTP Validation at Thu Jul  4 06:22:35 EDT 2013 ....'
+ echo 'Command: ausa'
+ DATABASE=UAD1
+ cd /purge/ausa/extracts
+ echo 'Path : /purge/ausa/extracts'
Path : /purge/ausa/extracts
+ echo 'MF_File is : extvalid.lst'
MF_File is : extvalid.lst
+ '[' -f extvalid.wrk ']'
+ rm extvalid.wrk
+ '[' -f extvalid.lst ']'
+ echo 'Extract validation file extvalid.lst not found.'
+ exit 2

I'd bet the file being read contains CR (0x0D, <carriage return>, ^M) terminators.

1 Like

when I run the script via sh -x, I find \r after the value and that is causing the problem.

Due to \r it is unable to suffix .ext.sent

Could you suggest how to remove that.

Thanks,
Preeti

a) don't use MS tools to edit files
b) run dos2unix on the input file
c) tr -d '\r' <inputfile # may not work on all implementations

Actually, it does concatenate the strings. But you can't see that, as, when echo ed or print ed, the \r makes the remaining output start at the begin-of-line thus overwriting the first part of the string. Pipe the output through od or hexdump to see the single chars in it.