Remove ^M (CR) from Unix Files


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Remove ^M (CR) from Unix Files
# 1  
Old 07-15-2005
Remove ^M (CR) from Unix Files

Is there any way we could remove the "^M" from files on unix?

and also what is the best way to count the TABS in a TAB delimited file per record?

Thanks,
AC
# 2  
Old 07-15-2005
Quote:
Originally Posted by acheepi
Is there any way we could remove the "^M" from files on unix?
search the archives
Quote:
Originally Posted by acheepi
and also what is the best way to count the TABS in a TAB delimited file per record?
Code:
nawk -F"`/bin/echo '\t'`" '{print FNR, NF}' myFile

# 3  
Old 07-17-2005
You can try also :
cat file1 | tr -d "\r" > file2

Regards,
Nir
# 4  
Old 07-17-2005
Quote:
Originally Posted by nir_s
You can try also :
cat file1 | tr -d "\r" > file2

Regards,
Nir
Is cat needed?

Code:
tr -d "\r" <file1 >file2

# 5  
Old 07-18-2005
Code:
strings file_name > file_name_without_control_chars

Cheers
# 6  
Old 07-18-2005
sed 's/^M$//' <file> > <newfile>

( "^M" has to be entered as CTRL-M)

Alternative possibilities include "dos2unix" and similar programs.

Nearly every program is able to remove trailing LF-characters it seems. ;-))

bakunin
# 7  
Old 07-18-2005
You have to use dos2unix (linux) or dos2ux (hp-ux) for this. Encoding is getting different from dos to unix with ^M character.

hth.
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

How to remove ^M character in file in UNIX?

I have file with controlM (^M) character. i just wanted to run the script after removing the same through script. Thanks in Advance Ganesh. (1 Reply)
Discussion started by: Ganesh L
1 Replies

2. Solaris

Command to remove existing files in the tar files in Solaris 10

Hi, I am using solaris 10 OS.Please help me out with the commands needed in below two scenarios. 1)How to delete the existing files in the tar file. suppose i have a main tarfile named application.tar and it contains a file called ingres.tar. what is the command to remove ingres.tar... (2 Replies)
Discussion started by: muraliinfy04
2 Replies

3. Shell Programming and Scripting

How to remove ^I character from a UNIX file ?

Hi When i used :set list in vi , i have seen a lot ^I characters in my file. Could anyone please help me how to remove this characters ? Issue : When i used awk to combine two file (one of the file has ^I characters) then my output is different than what am expecting, one of column being... (2 Replies)
Discussion started by: rakeshkumar
2 Replies

4. Shell Programming and Scripting

Remove <CR><LF> from the dat file in unix

Hi, The source system has created the file in the dat format and put into the linux directory as mentioned below. I want to do foloowing things. a) Delete the Line started with <CR><LF> in the record b)Also line ...........................................................<CR><LF> ... (1 Reply)
Discussion started by: mr_harish80
1 Replies

5. UNIX for Advanced & Expert Users

how to remove the files along with its link files

How to remove the files along with its link files either hardlink or softlink? (1 Reply)
Discussion started by: Ramesh_srk
1 Replies

6. Shell Programming and Scripting

compare two files and to remove the matching lines on both the files

I have two files and need to compare the two files and to remove the matching lines from both the files (4 Replies)
Discussion started by: shellscripter
4 Replies

7. Shell Programming and Scripting

remove \x0a in unix

hi all, i have a flat file delimited by pipe (|), and i'm loading it to sybase, the problem is when i do a select to the table of the database, the last field has new line ascii (\x0a): 38,'0\x0a ' 88,'076004074028\x0a ' 27,'076004075023\x0a ' how can i remove the \x0a from... (1 Reply)
Discussion started by: DebianJ
1 Replies

8. Shell Programming and Scripting

how to get remove file in unix

hi all, can u plz let me know how to get a file which is being deleted or removed using rm command in unix thanks in advance bali (1 Reply)
Discussion started by: balireddy_77
1 Replies

9. UNIX for Dummies Questions & Answers

To remove the extra spaces in unix

Hi... I am quite new to Unix and would like an issue to be resolved. I have a file in the format below; 4,Reclaim,ECXTEST02,abc123,Harry Potter,5432 6730 0327 5469,0603,,MC,,1200,EUR,sho-001,,1,,,abc123,1223 I would like my output to be as follows; 4,Reclaim,ECXTEST02,abc123,Harry... (4 Replies)
Discussion started by: Sho
4 Replies

10. HP-UX

Want to remove files from unix directory

Dear All I am basic user of Unix. i woul like to delete some files (basically 05 and 0801111105) from unix directories but unable to delete it I tried all option. rm , rm -f etc.. but not succeed. Infact it also not allowing me to use chmod option so that i can grant 777 option to... (1 Reply)
Discussion started by: yogi_chavan
1 Replies
Login or Register to Ask a Question