System Administration
cancel
Showing results for 
Search instead for 
Did you mean: 

how can I identify files that contain controlMs on my box...

SOLVED
Go to solution
Manuel Contreras
Regular Advisor

how can I identify files that contain controlMs on my box...

I have a sql file that contains controlM characters:
-rwxr-xr-x 1 root sys 6311 Feb 20 12:35 asciiFILE.sql


found a tr command, which easily removes these unwanted controlM characters

# cat asciiFILE.sql | tr -d '\015' > nonasciifile.sql
-rw-r--r-- 1 root sys 6097 Feb 20 12:36 nonasciiFILE.sql


rather then perform this tr command on every single sql file on my box...is there a way to identify which files contain the controlM characters?

file didn't work:

# file asciiFILE.sql
asciiFILE.sql: ascii text

# file nonasciiFILE.sql
nonasciiFILE.sql: ascii text


any assistance is appreciated.
manuel
5 REPLIES
Manuel Contreras
Regular Advisor

Re: how can I identify files that contain controlMs on my box...

sample of asciiFILE.sql:

^M
--alter session set sql_trace = true ; ^M
^M
^M
declare ^M
^M
-- cursor to loop thru all the valid lockboxes ^M
^M
cursor lock_cur is ^M
select lockbox_number ^M
from ar_lockboxes_all ^M
where status = 'A' ; ^M
^M


James R. Ferguson
Acclaimed Contributor

Re: how can I identify files that contain controlMs on my box...

Hi Manuel:

This results from moving a Windows-based file to your Unix server via FTP in BINARY mode instead of ASCII mode (which handles the conversion automatically). Windows denotes end-of-lines with a linefeed+carriage-return whereas Unix uses a simple linefeed.

On HP-UX simply use:

# dos2ux file > file.new

Inversely, to ADD a carriage-return do:

# ux2dos file > file.new

Regards!

...JRF...
Avinash20
Honored Contributor

Re: how can I identify files that contain controlMs on my box...

You could use "dos2ux" command to convert the files without ^M character

Also this issue might occur if you have transferred the file in ASCII format instead of Binary format.

Try
# grep '^M' //*/*
"Light travels faster than sound. That's why some people appear bright until you hear them speak."
James R. Ferguson
Acclaimed Contributor
Solution

Re: how can I identify files that contain controlMs on my box...

Hi (again) Manuel:

> rather then perform this tr command on every single sql file on my box...is there a way to identify which files contain the controlM characters?

Yes, you could use:

# perl -nle 'print "CR Present!" and exit if m{\r}' file

Regards!

...JRF...
Manuel Contreras
Regular Advisor

Re: how can I identify files that contain controlMs on my box...

> perl -nle 'print "CR Present!" and exit if m{\r}' asciiFILE.sql
CR Present!

> perl -nle 'print "CR Present!" and exit if m{\r}' nonasciiFILE.sql


thanks James, just what I was looking for...

happy friday everyone :)