why ^M in my file?


 
Thread Tools Search this Thread
Top Forums UNIX for Dummies Questions & Answers why ^M in my file?
# 1  
Old 01-07-2009
why ^M in my file?

I have downloaded one csv file from my AIX box and edited using Text Pad, and uploaded thru SecureFX, If I see the file using vi command I can see ^M in end of the line, if open again in text pad there are lot of new lines. How to fix this issue? where is the problem? Text pad or SecureFX?
# 2  
Old 01-07-2009
man unix2dos
or
man dos2unix
# 3  
Old 01-07-2009
Quote:
Originally Posted by redlotus72
I have downloaded one csv file from my AIX box and edited using Text Pad, and uploaded thru SecureFX, If I see the file using vi command I can see ^M in end of the line, if open again in text pad there are lot of new lines. How to fix this issue? where is the problem? Text pad or SecureFX?

Sadly, my AIX box does not have dos2ux <sigh> - which I have used successfully on other systems.

The problem comes up that dos/windows uses two characters to indicate end-of-line. Unix uses one. What you are seeing in UNIX is the extraneous (at least to it) character.

Try transmitting the file in TEXT mode. that should convert between the two systems.

Else, find a way to use sed to get rid of the extra character.
# 4  
Old 01-07-2009
If you transfer via ftp or sftp that problem will be automatically fixed.

You can search and replace in VI to take care of it:
:1,$s/^M//g
Padow
# 5  
Old 01-07-2009
This will work on all unix flavors:

Code:
tr -d '\r' < problem_file.txt > fixed_file.txt

You can write a quick script in ksh on your aix box that is a little easier:

Code:
#!/bin/ksh
#
# dos2unix.sh - Removes trailing carriage returns from text files
#
# Usage: dos2unix.sh <file>

tmp=/tmp  # Define temporary work directory for temp files

if [ ! "$1" ]
then
    echo "Usage: dos2unix.sh <file>"
    exit 1
fi

if [ -f $1 ]
then
    tr -d '\r' < $1 > $tmp/$1.$$
    mv $tmp/$1.$$ $1
else
    echo "Not a valid file: $1"
    exit 1
fi


Last edited by stanleypane; 01-07-2009 at 02:06 PM..
# 6  
Old 01-07-2009
Maybe a quicker solution: see if TextPad can save the file with UNIX-style line endings. Most editors can do so.
# 7  
Old 01-07-2009
use unix2dos or sometimes u can try reading it in ASCII format and it wud fix the issue
 
Login or Register to Ask a Question

Previous Thread | Next Thread

3 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Shell script (sh file) logic to compare contents of one file with another file and output to file

Shell script logic Hi I have 2 input files like with file 1 content as (file1) "BRGTEST-242" a.txt "BRGTEST-240" a.txt "BRGTEST-219" e.txt File 2 contents as fle(2) "BRGTEST-244" a.txt "BRGTEST-244" b.txt "BRGTEST-231" c.txt "BRGTEST-231" d.txt "BRGTEST-221" e.txt I want to get... (22 Replies)
Discussion started by: pottic
22 Replies

2. Shell Programming and Scripting

Compare 2 text file with 1 column in each file and write mismatch data to 3rd file

Hi, I need to compare 2 text files with around 60000 rows and 1 column. I need to compare these and write the mismatch data to 3rd file. File1 - file2 = file3 wc -l file1.txt 58112 wc -l file2.txt 55260 head -5 file1.txt 101214200123 101214700300 101250030067 101214100500... (10 Replies)
Discussion started by: Divya Nochiyil
10 Replies

3. Shell Programming and Scripting

Match list of strings in File A and compare with File B, C and write to a output file in CSV format

Hi Friends, I'm a great fan of this forum... it has helped me tone my skills in shell scripting. I have a challenge here, which I'm sure you guys would help me in achieving... File A has a list of job ids and I need to compare this with the File B (*.log) and File C (extend *.log) and copy... (6 Replies)
Discussion started by: asnandhakumar
6 Replies
Login or Register to Ask a Question