tr command fail to work in script


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting tr command fail to work in script
# 1  
Old 09-07-2010
tr command fail to work in script

Hi,
I has the following command in the script. This command works fine if I execute on command prompt. If I run the script, this is not working as expected (deleting CR).
Code:
tr -d "\015" < ${FilePath}/${FileName} > ${FilePath}/${File_Prefix}.csv

I could not figure out whats wrong. Please let me know whats wrong in this.

Thanks & Regards
Kavuri

Last edited by radoulov; 09-08-2010 at 11:28 AM.. Reason: Code tags, please!
# 2  
Old 09-07-2010
Hi.

Did you export the variables FileName and FilePath prior to running the script?
# 3  
Old 09-07-2010
Hi Scott,
When I run through command line I had substituted the variables.

When I am running the same command from script, I had defined the variable names at the beginning of the script.

FilePath=/dir_path/
FileName=file1.csv

Thanks
Kavuri
# 4  
Old 09-07-2010
What about File_Prefix?
# 5  
Old 09-08-2010
I did defined File_Prefix as well. just as an example I had given some dummy values.

Thanks
Kavuri
# 6  
Old 09-08-2010
Assuming that your original file (which I shall call "filename") is a MSDOS text file with a carriage-return character in every record.
What is the output from this sequence of commands both from the command prompt and from a shell script. I'm assuming that your shell is not "csh" or "tcsh".
The "sed -n l" command just makes control codes visible.

Code:
filename="insert_the_name_of_your_original_file"
echo "Shell is:"
echo "${SHELL}"
echo "Original file"
head -1 "${filename}" | sed -n l
echo "Conversion 1"
head -1 "${filename}" |tr -d "\015" | sed -n l
echo "Conversion 2"
head -1 "${filename}" |tr -d '\015' | sed -n l
echo "Conversion 3"
head -1 "${filename}" |tr -d "\r" | sed -n l

# 7  
Old 09-08-2010
Hi,
I see these DOS characters are not consistantly in all the lines. They appear in some lines only. As the below code will check for the CR in first line only, it could not help us in figuring out the issue.

I had seen some more characters like vt (vertical tab - 0x0b) etc.. as well.

I got the codes to remove all these DOS characters but it is working only sometimes.

I think we need to check for the previous command execution status before the next command executes in the script. Can someone explain more on this?

Thanks
Kavuri
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Programming

Why does fflush(stdin) fail to work ?

#include <stdio.h> #include <stdlib.h> int main(void) { double number; while (scanf("%lf", &number) != 1) { printf("Error\n"); } printf("%lf\n", number); return 0; } Look at the... (3 Replies)
Discussion started by: chihuyu
3 Replies

2. Shell Programming and Scripting

If Telnet fail abort other command..??

Hi Team, I my script i telent my node ip and after loging i run some commands...But some time login fail so i want to stop script at that time.. CONFIG_CHNG.sh printf 'Please Input Node ID : ' read node node="$node" #exec > node_log_$node.log 2>&1 #set -x >... (2 Replies)
Discussion started by: Ganesh Mankar
2 Replies

3. Shell Programming and Scripting

Ssh remote command doesn't work from script file

I have 10 application servers in a distributed architecture generating their own application logs. Each server has application utility to continuously tail the log. for example following command follows tails and follows new logfiles as they are generated server1$ logutility logtype When I run... (8 Replies)
Discussion started by: indianya
8 Replies

4. AIX

Commands to call script work from command line but not from Cron entry

My first post evidently did not materialize so I posted it again: Runnning a cron job every 5 mins to send data files to a state facility. My original cron entry at worked fine: 01,06,11,16,21,26,31,36,41,46,51,56 * * * * /home/sftpuser/stateinoc-from-appname.ksh Somewhere I have a... (1 Reply)
Discussion started by: Skyybugg
1 Replies

5. UNIX for Dummies Questions & Answers

[SOLVED] Mv command doesnt work in shell script

Hi All, i created the below script to move file with xml extension from one directory to another,but the mv command is not working inside the shell script, #!/us/bin/ksh filepath="/apps/extract" filename="*.xml" foldername=2191POB000_$(date +%Y%m%d%H%M%S) mkdir -p "$filepath/$foldername"... (3 Replies)
Discussion started by: Radhas
3 Replies

6. UNIX for Dummies Questions & Answers

How to work command 'cd' in shell script?

I have simple script. like that, I am working on /usr/local/src and also under src folder there is a ft folder #!/bin/ksh #!/bin/bash dirpath="/usr/local/src/ft" echo $dirpath cd $dirpath echo displays ok "/usr/local/src/ft" but that doesn't enter "ft" folder. stays in current... (4 Replies)
Discussion started by: F@NTOM
4 Replies

7. UNIX for Dummies Questions & Answers

find command in shell script doesn't work

Hello all, Something strange going on with a shell script I'm writing. It's trying to write a list of files that it finds in a given directory to another file. But I also have a skip list so matching files that are in that skip list should be, well uhm, skipped :) Here's the code of my... (2 Replies)
Discussion started by: StijnV
2 Replies

8. Shell Programming and Scripting

Banner causes scp to fail from script but not command line.

Hi, We have an interesting issue which is similar to the one in this thread, but that never provided a full answer. - Ohh apparently I can't post URLs till I have 5 posts, sorry. We have a simple script that copies files from one shelf to the other. Both shelves have an ssh banner defined. ... (3 Replies)
Discussion started by: RECrerar
3 Replies

9. UNIX for Dummies Questions & Answers

Command work but not in SH script

Command works but not in SH At terminal if i type: scp test.tar.gz user1@server2:/home/user Everything run smoothly (keyed, no password need) At script , test.sh #!/bin/sh scp test.tar.gz user1@server2:/home/user Nothing happen and clue ? ? ? ? ? (3 Replies)
Discussion started by: cititester
3 Replies

10. Shell Programming and Scripting

command line work script doesn't

Hello, I'm stuck and confused as to why when I execute things form the command line it works but when in a script it doesn't. My script: ### creating a lock on the console touch /var/run/console.lock chmod 600 /var/run/console.lock echo "$User" >>... (2 Replies)
Discussion started by: larry
2 Replies
Login or Register to Ask a Question