The UNIX and Linux Forums  


Go Back   The UNIX and Linux Forums > Top Forums > UNIX for Advanced & Expert Users
.
google unix.com




View Single Post in the UNIX and Linux Forums - Click on the Thread or Permalink to View Entire Thread -->
  #1 (permalink)  
Old 04-12-2008
kodermanna kodermanna is offline
Registered User
  
 

Join Date: Jan 2008
Posts: 11
Problem with tr command a-z 0-9

Hi experts,

I am getting a strange result when using the tr command.
I am using tr to change file names extensions created by split command ( from aa, ab, ac etc to 00, 01, 02 etc). If I run the script from command prompt I get the expected results but when I do it thru a cron tab and invoked from a perl scriipt i get strange results. For example ab gets converted to 08 but aa gets converted to 00.

+ old_ext=ae
+ print Old Extension ae
Old Extension ae
+ + tr a-z 0-9
+ echo ae
new_ext=0e
+ print New Extension 0e
New Extension 0e

for ab new_ext is coming as 08 from there onwards it is 0c, 0d,0e like that.


Here is the relevant portion of the code.
for i in `ls ${base_file_name}.a*`
old_ext=${i##*.}
print "Old Extension " $old_ext
new_ext=`echo $old_ext | tr 'a-z' '0-9'`
print "New Extension " $new_ext
done

any help would be highly appreciated as I spent many hours on this. I tried severl approaches like putting eval in front of echo but couldn't get this working.