hi,
I have a requirement in that i need to process a input file
The problem is, the input file sometimes it is coming in dos mode and some times it is coming in unix mode
The script which i have written will process the file only if it is in unix mode and it is not processing if the file is in dos mode
Is there any method to check whether the input file is in dos mode or in unix mode within the script itself (while processing)
So that i can handle the same in my script
How exactly is the file coming to the server? Is it through FTP? If so, what mode are you using for transferring? ASCII or BINARY?
Note that if the FTP transfer mode is ASCII, then the files might have ^M characters or square boxes appended at the end of each line, which may result in the failure of your script. Hence, BINARY mode of FTP transfer is always preferred.
hi,
i am not asking for tr -d '\r' < infile > outfile
if you are inside shell script, from the script itself you can check whether a file is having execute, read, write permissions
like that i am asking. From within a shell script i want to check whether the input file is in dos mode or unix mode
My intention is in whatever format (dos or unix) they send the file to unix box my script has to check the type and if it is not matching it has to convert it into unix mode with in the shell script while processing
The below few lines are from one file called retst.out
I just copied few of the lines by opening the file in vi mode
you can see the [dos] in the lines below (in vi editor)
Just for clarification: the term "mode" in UNIX usually refers to the permission bits set (read/write/execute). What you mean would be the line termination style (DOS/Windows: \r\n, UNIX: \n, Apple: \r) or the file encoding.
To convert a file from DOS style to UNIX style, the commands suggested by rakeshou should work just fine.