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 Chris Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

How to get rid of control M on Unix... 1

Status
Not open for further replies.

kumariaru

IS-IT--Management
Mar 9, 2006
61
AU
Hi All,
I have a script which takes multiple files from a UNIX server and renames them and put to a Unix folder.

Below is the script:


SrcDir=$1

cd $SrcDir
ls *_*.txt | nawk '
{x=$0;sub(/_.*\.txt$/,".txt",x); printf "cp %s /ap/test/cat/%s\n",$0,x}
' |sh -v


I am successfully moving all the files with renames.But I have an issue with the ^M to few files. I can see that source directory files are not having ^M. But when I run this script and copy the files , I can see that few files are having ^M's at the end.
I want all the files in one format(Unix format).
How can I come out of this problem...
Thanks in advance....
 
There is a utility called dos2unix and its counterpart called unix2dos. Its sole job is to remove those pesky ^Ms.

You can also remove them via tr:

Code:
cat some.file | tr -d "\015" > some.new_file

some.new_file will now have all the control Ms removed.

Add a little color to your PUTTY terminal: faq52-6627
 

Just a thought. Does the script still work if the "\n" in the "printf" is replaced by a ";"?

 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top