Operating System - HP-UX
1834593 Members
4190 Online
110069 Solutions
New Discussion

how to get rid of control M characters!!!!

 
Sachin_29
Advisor

how to get rid of control M characters!!!!

Hi :
I am parsing a file and writing part of it to another file
echo $PATH "," >$outfile
I am getting a ^M character before "," in the outfile.. i checked the $PATH it doesnt have the character.. is there any way i could get rid of it in a script itself?
17 REPLIES 17
Victor Fridyev
Honored Contributor

Re: how to get rid of control M characters!!!!

cat outf1 |col -b > outf2

HTH
Entities are not to be multiplied beyond necessity - RTFM
Michael Tully
Honored Contributor

Re: how to get rid of control M characters!!!!

Have a look at the 'dos2ux' program. It will remove these.
Anyone for a Mutiny ?
Michael Tully
Honored Contributor

Re: how to get rid of control M characters!!!!

All that really should happen is that the output of your PATH should end in the file with a ',' at the end.

Check your terminal type. This is most likely the cause.
Anyone for a Mutiny ?
YoungHwan, Ko
Valued Contributor

Re: how to get rid of control M characters!!!!

1. Convert your file to unix file
If original file name is aaa.sh.
# dos2ux aaa.sh > aaa.txt

2. Rename converted name to original file name.
# mv aaa.txt aaa.sh
D Block 2
Respected Contributor

Re: how to get rid of control M characters!!!!

there is a unix command called STTY

stty raw
stty -raw

I haven't played w/ this in a while, but when you Terminal I/O is put into RAW mode, you should see the extra character ^M before the next-line is printed.

Unix uses ASCII '\n' to imply both line-feed and carriage-return. Well, in raw-mode, you see both the line-feed ascii and carriage-return ascii.

In dos, this is different. also, in unix, when you are in 'raw' terminal i/o mode, you see both of these in output files.

try a: cat -v


for more reading see: termio(7) and stty(1)
Golf is a Good Walk Spoiled, Mark Twain.
ranganath ramachandra
Esteemed Contributor

Re: how to get rid of control M characters!!!!

echo -n $PATH "," >$outfile
 
--
ranga
hp-ux 11i v3[i work for hpe]

Accept or Kudo

Petr Simik_1
Valued Contributor

Re: how to get rid of control M characters!!!!

^M is windows marker for
this typically happen when you FTP ascii file from windows ws. Then you have to dos2ux filename > file
on other hand in windows if you have squares instead of cr use ux2dos.

Bharat Katkar
Honored Contributor

Re: how to get rid of control M characters!!!!

Hi,

# cat filename | col -bx > textfile

This should also help.
Regards,
You need to know a lot to actually know how little you know
Sachin_29
Advisor

Re: how to get rid of control M characters!!!!

Somehow none it doesnt work probably its my fault I forgot to mention its AIX os..
sorry about that
any ideas?
Kent Ostby
Honored Contributor

Re: how to get rid of control M characters!!!!

If its a one time thing, you can go into vi and do:

:1,$:s/ctrl-Vctrl-M//

best regards,

Kent M. Ostby
"Well, actually, she is a rocket scientist" -- Steve Martin in "Roxanne"
Sachin_29
Advisor

Re: how to get rid of control M characters!!!!

no its not a one time thing i am creating these files thru script and then reading these files later because of these characters i am haing problem
thanks
Cesare Salvioni
Trusted Contributor

Re: how to get rid of control M characters!!!!

try
echo "${PATH}." | sed 's/^M//g' > $outfile

to write ^M use ctrl-V ctrl-M

hope this helps
Rick Garland
Honored Contributor

Re: how to get rid of control M characters!!!!

cat $FILE | tr -d '/015' > $FILE2
mv $FILE2 FILE1

Can use the tr command to delete the characters as well. The octal /015 is translated to the ^M character.
Sachin_29
Advisor

Re: how to get rid of control M characters!!!!

I am getting my path
Sorry but doesnt help
My code

while read -r temp
do
Path="`echo $temp |awk '{print $4}'`"
echo $Path","$somethin>$outfile
done $1
In the outfile i am getting


/tmp/something^M,something
/tmp/something1^M,something1
/tmp/something2^M,something2
....

Later I read the outfile to use the Path
while read -r line
do
echo $line
done<$outfile


i am not sure whats wrong?
thanks for your help guys sirry didnt work ..
anything else i can try?

ranganath ramachandra
Esteemed Contributor

Re: how to get rid of control M characters!!!!

dont use the '-r' option of read.
 
--
ranga
hp-ux 11i v3[i work for hpe]

Accept or Kudo

Muthukumar_5
Honored Contributor

Re: how to get rid of control M characters!!!!

Your input file may be with dos format. By normally it will contains additional character \r with that. You have to change the format of file to hpux so that ^M will not be coming.

You can know the change as,

--- in your script ---


Path="`echo $tmp | awk '{ print $4 }'`"
echo $path | od -dc

Path1="`echo $tmp | awk '{ print $4 }' | dos2ux`"
echo $path | od -dc

And more check this link to know more about the problem,
http://forums1.itrc.hp.com/service/forums/questionanswer.do?threadId=637940

It will work now.
Easy to suggest when don't know about the problem!
vinodan
Advisor

Re: how to get rid of control M characters!!!!

Hi
I think you have taken the i/p file
from windows.In unix carriage (^M) is not there.But in windows it has.when you copy any file from windows to unix this problem happens.


As per my opinion
dos2ux ip_file >op_file
is the best way

i have seen one perl script also .But right now i don't have


regards
vinod