Page 1 of 2

How to handle Control M Character

Posted: Mon Jan 29, 2007 1:06 pm
by kool78
HI Guys,

Did anyone come across handling Control M charaters .

I have a .csv file and when i look into it, it has a CntrlM(^M) character at the end of each record..

i tried different delimiters for cntl m but it didnt work out....is ther any work around for this issue..

thanks
shisheer

Posted: Mon Jan 29, 2007 1:08 pm
by chulett
^M is a <CR> and indicates DOS style record terminators.

Re: How to handle Control M Character

Posted: Mon Jan 29, 2007 1:16 pm
by pavankvk
kool78 wrote:HI Guys,

Did anyone come across handling Control M charaters .

I have a .csv file and when i look into it, it has a CntrlM(^M) character at the end of each record..

i tried different delimiters for cntl m but it didnt work out....is ther any work around for this issue..

thanks
shisheer
u can clean the file before processing using sed command.

Posted: Mon Jan 29, 2007 1:20 pm
by narasimha
Or vi the file and use substitution to remove all the ^M's

Code: Select all

:%s/^M//g 

Posted: Mon Jan 29, 2007 4:04 pm
by ray.wurlod
... or set the Final Delimiter property to \R

... or create a dummy Char(1) column and set it's "drop on import" property to True

:idea: There's always more than one way to do something in DataStage.

Posted: Mon Jan 29, 2007 4:30 pm
by kool78
Hi all,

Thanks for the replies...

I dont want to process the file before...

but i was trying the options mentioned by Ray...i used \R but still im unable to view the data....its throwing the error as delimiter for hte filed(last filed) is not found..

it would be grt if can you throw more light on this ray...

thanks

Posted: Mon Jan 29, 2007 4:42 pm
by ray.wurlod
Which of the methods did you try? The second (create an extra column) will fail with the message you got, because there is no actual delimiter character between the last column and the \r character.

What is the data type of the last field in your data record?

Did you try setting the final delimiter property to \r ? If it won't take more than one printable character, try using 013 (the decimal value of the ASCII code point).

Posted: Mon Jan 29, 2007 4:47 pm
by kool78
ray.wurlod wrote:Which of the methods did you try? The second (create an extra column) will fail with the message you got, because there is no actual delimiter character between the last column and the \r character.
...
Hi ray

I tried the first method..

have set the Final Delimiter property to \R but didnt work out..

one morething i observed is ..when i used record delimiter strins as : DOS Format..it was working fine..

but im not sure whether if the source file is ftp'd from windows to unix..does it have unix newline or dos format...


thanks

Posted: Mon Jan 29, 2007 4:54 pm
by ray.wurlod
Last time I looked (7.5.1), "DOS format" was not available for record delimiter when running on UNIX platform. Otherwise I would have cited that as the appropriate technique.

The only way to know what's there is to look at the actual characters. If you have a hex editor, such as UltraEdit, use that. Otherwise you can use the UNIX od command.

Code: Select all

head -3 filename | od -xc

Posted: Mon Jan 29, 2007 5:26 pm
by chulett
ray.wurlod wrote:Last time I looked (7.5.1), "DOS format" was not available for record delimiter when running on UNIX platform. Otherwise I would have cited that as the appropriate technique.
Wasn't that what I quoted from the Developer's Guide? :?

Posted: Mon Apr 02, 2007 4:26 am
by Th3Und34D-
Hi ray

I tried the first method..

have set the Final Delimiter property to \R but didnt work out..

one morething i observed is ..when i used record delimiter strins as : DOS Format..it was working fine..

but im not sure whether if the source file is ftp'd from windows to unix..does it have unix newline or dos format...

I too faced similar problem.. I think it is due to the file FTP from windows to unix server.

While ftp'ing the file use command "ascii" (by default it is "bin" - binary), and then ftp the file... Use SSH Clients and ftp the file in ASCII format.. This should solve the problem..

Regards,
Asish

Posted: Mon Apr 02, 2007 6:29 am
by chulett
Th3Und34D- wrote:I too faced similar problem.. I think it is due to the file FTP from windows to unix server.
Typically - yes. Or sometimes people map a UNIX drive in Windows and just drag and drop files. :roll:

ps. That won't "solve" the problem, per se. To solve it one would need to be able to read and handle DOS files properly. An 'ascii' ftp transfer would eliminate the need to solve the problem. :wink:

You can try this

Posted: Mon Apr 02, 2007 8:17 am
by smrutiranjannayak
Hi ,

you can try the following option :

While saving the file in Unix ( i guess u r using this platform) just type the below command

%s/^M//

Cheers
:lol:

Posted: Mon Apr 02, 2007 9:11 am
by ray.wurlod
Investigate the Record Delimiter String property (rather than the Record Delimiter property). Specify as \r\n

Haaa... Finally i got a resolution for this.

Posted: Mon Apr 02, 2007 11:26 pm
by Th3Und34D-
I got a solution. It solved my purpose of removing ^M. :)

Use Iconv("Column where ^M is present", "MCP")

With MCP option ur problem will b solved ... :D

Regards,
Asish Koyya