How to identify whether the script is in Unix format or not ?


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting How to identify whether the script is in Unix format or not ?
# 1  
Old 07-04-2012
MySQL How to identify whether the script is in Unix format or not ?

Hi All,
I have the below scenario in my environment
Developers used to copy file from windows to Linux box. Some time on the copied file developers miss to run the dos2unix utility. Because of this script gets failed during the execution. Most of the failures are due to the dos2unix format issue.


Is there any way to identify if the script is not in a UNIX format ?
# 2  
Old 07-04-2012
Hi

The file command will help you in this.

a is a unix file

Code:
$ file a
a: ASCII text

b is a file containing the ctrl-M characters at the end.

Code:
$ file b
b: ASCII text, with CRLF line terminators

Guru.
# 3  
Old 07-04-2012
Thanks Guru..

I transfered a script from windows to unix and tried the file command.

Quote:
file te.sh
te.sh: Bourne-Again shell script text executable
But when i try to execute got the below error.

Quote:
./te.sh
-bash: ./te.sh: /bin/bash^M: bad interpreter: No such file or directory
# 4  
Old 07-04-2012
use dos2unix command
# 5  
Old 07-04-2012
Quote:
Originally Posted by itkamaraj
use dos2unix command
Yes, i agree dos2unix will convert the file from dos to UNIX format. But i want to execute dos2unix only if the file is not in UNIX format.
# 6  
Old 07-04-2012
Hi

You can do something like this.

THe file 'file1' has the Ctrl-M character in every line:


Code:
$ cat -v file1
#!/usr/bin/bash^M
echo welcome^M

You can check for the count of ctrl-M characters :


Code:
$ grep -c '^M$' file1
2

Note: ^M = Ctrl-V + Ctrl-M
# 7  
Old 07-04-2012
@kalpeer: See if this link helps.
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

UNIX script email to outlook report format

I have a ksh script that emails a report to outlook from a Unix Solaris. On server the report formatted perfectly. However, the email version the format is not. On the server report looks like this: TN Region Old SPiAD Server Order/Req Local Status NAAC Status Request Date New... (1 Reply)
Discussion started by: mrn6430
1 Replies

2. Shell Programming and Scripting

Identify lines with wrong format in a file and fix

Gurus, I have a data file which has a certain number of columns say 101. It has one description column which contains foreign characters and due to this some times, those special characters are translated to new line character and resulting in failing the process. I am using the following awk... (4 Replies)
Discussion started by: tumsri
4 Replies

3. Shell Programming and Scripting

UNIX shell script to format output report

i am new to unix shell scripting, could someone please help me. i was asked to develop a unix script and requirement of the script is as follows: 1. In source directory, if any new files are being dropped by external system then an email should be sent out with a message saying "files are... (3 Replies)
Discussion started by: crefi1545
3 Replies

4. Shell Programming and Scripting

Change the date and time format in UNIX script.

Hi, I am extracting a date string from the source file like this : 06/05/2014 16:04:00 I want to change it to 05-JUN-14 04.05.00.000000000 PM I basically store the date in a variable. I got solutions to change date in dd-mmm-yyyy format using tr but I guess it works only with the "date"... (8 Replies)
Discussion started by: Varshha
8 Replies

5. UNIX for Dummies Questions & Answers

How to retrive data from DB(Aqua studio) in CVS format using UNIX script?

I am using aqua studio DB. I need to retrive the data from my database using uxin script in .csv format. i am using select query along with the joins. my o/p in the DB is of the below format. Cycle IDCycle StatusRecord 98N-0000ACV23-3636FCliet Level (Af)Success1689393HF-J7879-09090RCliet Level... (1 Reply)
Discussion started by: Mugivz
1 Replies

6. UNIX for Dummies Questions & Answers

Use Regex to identify / format a complex string

First of all, please have mercy on me. I am not a noob to programming, but I am about as noob as you can get with regex. That being said, I have a problem. I've got a string that looks something like this: Publication - Bob M. Jones, Tony X. Stark, and Fred D. Man, \"Really Awesome Article... (1 Reply)
Discussion started by: egill
1 Replies

7. Shell Programming and Scripting

Need a unix script to convert date into Julian format in a text file

The 6th & 7th column of the text files represents date & time. I need this to be converted in julian format using command "date +%s -d <date>". I know the command, but dont know how to use it on the script 0 dbclstr-b IXT_Web Memphis_Prod_SQL_Full Memphis-Prod-SQL-Full-Application-Backup... (4 Replies)
Discussion started by: ajiwww
4 Replies

8. Shell Programming and Scripting

Converting windows format file to unix format using script

Hi, I am having couple of files which i used to copy from windows to Linux, so now in case of text files (CTRL^M) appears at end of line. I know i can convert this windows format file to unix format file by running dos2unix. My requirement here is that i want to do it automatically using a... (5 Replies)
Discussion started by: sarbjit
5 Replies

9. Shell Programming and Scripting

Format a file through unix script

Hi, Can you please help me out about how to format a .csv file through unix script? Set of complete commands would be useful or also share few links if available. ---------- Post updated at 09:00 PM ---------- Previous update was at 08:59 PM ---------- I am talking about in terms of... (12 Replies)
Discussion started by: amit.mathur08
12 Replies

10. UNIX for Dummies Questions & Answers

Unix script to convert .csv file to.xls format

I have a .csv file in Unix box i need a UNIX script to convert the.csv files to.xls format. Its very urgent please help me. (1 Reply)
Discussion started by: moon_friend
1 Replies
Login or Register to Ask a Question