Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations TouchToneTommy on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

unable to run scripts get ^M' unexpected 2

Status
Not open for further replies.

jehig

MIS
Apr 15, 2001
4
CA
Hi guys,

I edited some scripts in windows and ftp to server now , now I am unable to run the scripts, I get the error below when I try to run them..

syntax error : `in^M' unexpected

So I go into the scripts and manually removed ^M' … , this now work okay.

But I am unable to run other scripts.. They come up with the same error… I look in the scripts and they are fine with no ^M' entries. But when I try to run them.. I get the same error above. This are scripts that I did not create or edit.
Please help
 
The ^M is a control character which you should be able to remove from the file by running it through dos2unix.

Ray

Even a bad day at the races is better than a good day at the office.
 
The ^M typically appears at the end of each line in a file that was created/edited in Windows/DOS world.

As always in the UNIX world there are multiple ways to solve a problem and my proffered solution to this one is with the tr command:

tr -d "\015" < dosfile > unixfile

where dosfile is the name of the input file containing the ^M characters and unixfile is the cleaned output file.

You could use dos2unix, but I have found in some cases this utility is not available on a particular system and tr is a universal command. There are other solutions too such as using sed.
 
Hi Berry,

I tried and got the error below.

please help

tr -d "\015" adapcctl_bck.sh adapcctl2.sh
Usage: tr [ -cds ] [ String1 [ String2 ] ]
 
Thanks this has been resolved see below

Example 2: Delete ^M character appended to the end of each line:

Let's say we have a file called test.csv that has an extra character ^M at the end of each line as illustrated below.

18,307,130,3504,12,70,1,8,0^M
15,350,165,3693,12,70,1,8,0^M
18,318,150,3436,11,70,1,8,0^M
16,304,150,3433,12,70,1,8,0^M
17,302,140,3449,11,70,1,8,0^M
15,429,198,4341,10,70,1,8,0^M

We can do use tr command as follows.

tr -d "\015" <test.csv > test1.csv

The new file test1.csv will look like this:

18,307,130,3504,12,70,1,8,0
15,350,165,3693,12,70,1,8,0
18,318,150,3436,11,70,1,8,0
16,304,150,3433,12,70,1,8,0
17,302,140,3449,11,70,1,8,0
15,429,198,4341,10,70,1,8,0
 
the fast way is to re ftp the file and make sure you use ascii for transfering the files. IF you use BIN then you will ge the ^M added to each line
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top