Hi,
I have getting problem with tr command, here is my problem
I Have file CntryCd_100302.wk
When i do like this it works fine
dt=`date +%y%m%d`
data_dir=/usr/apps/mp/script/UMTS/CRE2/data
tr "(){}[]\"'<>;&@" " " < CntryCd_100302.wk > CntryCd_100302.temp
But in the script i need to put like this to execute my script as shown below ..
when i do like this i am getting ouput file with no data and zero size ..
please let me know wat might be the problem ??
dt=`date +%y%m%d`
data_dir=/usr/apps/mp/script/UMTS/CRE2/data
tr "(){}[]\"'<>;&@" " " < $data_dir/CntryCd_100302.wk > $data_dir/CntryCd_100302.temp
Please let me know the issue ..
Thanks in advance ...
Raghav
Are you able to access the file correctly. Try doing
cat $data_dir/CntryCd_100302.wk
first and then
cat $data_dir/CntryCd_100302.wk | tr "(){}[]\"'<>;&@" " " > $data_dir/CntryCd_100302.temp
cheers,
Devaraj Takhellambam
Nila
March 4, 2010, 4:07am
3
Give me your input file contents.
Yes i am able to cat the file correctly .
Please find the content of the file
*->head CntryCd_100303.wk
000,Default Country,089999,Default Intl
020,EGYPT,089014,EGYPT
028,ST. HELENA,089014,ST. HELENA
20,EGYPT,089013,EGYPT
212,MOROCCO,089013,MOROCCO
213,ALGERIA,089013,ALGERIA
216,TUNISIA,089013,TUNISIA
218,LIBYA,089013,LIBYA
220,GAMBIA,089013,GAMBIA
221,SENEGAL,089015,SENEGAL
My question was - are you able to cat from within the script and not from the command prompt?
yes i am able to cat from script as well ..
i used this
cat $data_dir/CntryCd_100302.wk | tr "(){}[]\"'<>;&@" " " > $data_dir/CntryCd_100302.temp
but still i have CntryCd_100302.temp file empty
But when i do it ouside script ie from prompt within data_dir i am getting proper output.
Not sure where the problem is: To diagonise, can you try doing the below from the script
cat $data_dir/CntryCd_100302.wk > $data_dir/CntryCd_100302.temp
when i do this using cat
cat $data_dir/CntryCd_100302.wk > $data_dir/CntryCd_100302.temp
I am getting CntryCd_100302.temp file with all the content its proper .
but this was
tr "(){}[]\"'<>;&@" " " < $data_dir/CntryCd_100302.wk > $data_dir/CntryCd_100302.temp
working fine beore now its giving problem ..
Not getting wats the problem ..
Nila
March 4, 2010, 4:48am
9
I tried your code it is working fine with your input data.
dt=`date +%y%m%d`
data_dir=/mypath/bash
tr "(){}[]\"'<>;&@" " " < $data_dir/input > $data_dir/CntryCd_100302.temp
check if there are any hidden characters along with the above command. Perhapes, delete everything and rewrite again. I can't think of any reason why it shouldn't work? The culprit seems to be with the "tr" command.
Replace the lengthy tr command with a smaller one, for example -->
tr '[A-Z]' '[a-z]'
and see if that works.
If it works, replace double quote with single quaote and see.
But i dnt know whats wrong with my system it not working
->ls -ls input
2 -rw-rw-r-- 1 sysop msgproc 548 Mar 4 04:49 input
0 -rwxrwxrwx 1 sysop msgproc 0 Mar 4 04:52 input.temp*
I have replaced the lenghty one with ..
tr '[A-Z]' '[a-z]'
But still result same ..
its getting hard to diagnose it ..
pludi
March 4, 2010, 5:11am
14
This might sound like a dumb question, but what shell are you using for interactive use, and what shell is your script made for?
Thank a lot devtakh !
It is working fine
/usr/bin/tr is the key ...