How to concat line first and then removing the ^M character

hi

Someone can give me some clue or script in writing the below requirement

I am having 5 or 10 files of unix files which contain ^M charactes.

First we have to find ^M character and concat the line where it has broken and then we have to remove the ^M character from the uxix files.

Thanks

This is an already discussed topic

Refer this

Hari

I know the answer for removing the ^M ie..

awk '{ sub("\r$", ""); print }' filenew > newfilename which works for me .

First we have to search ^M and then concat the line and then remove . I am not able to find concat ideas.

Thanks

cat file1 file2 file3 file4..... > filenew
awk '{ sub("\r$", ""); print }' filenew > newfilename

or

cat file1 file2 file3 file4..... > filenew
dos2ux filenew > newfilename

Hari

In one file it has some lines like this

CDMA 1x=5102305, 2008-09-05 07:59:04, NAI=$QCMIPNAI^M
0000000000@vzw3g.com, MIN=0000007356, Config=62558-11 Verizon Std P3

Here first we have to make it in one line and then remove the ^M .

For me dos2unix is not working in Linux.

Thanks

Hi,
if it's a question of first removing RETURN, maybe pushing it through tr -d "\r" could help?

/Lakris

PS or tr "\r" " " and take it from there?

Try this:

sed '/^M$/N;s/^M\n//' file

To get the ^M character type <CTRL>-v and <CTRL>-m successively.

Regards

lakis

I am looking for a automatic script in finding the ^M and then doing concat the line .
Suppose in the file we have 10 lines with ^M .

I checked the tr command it is not working. Please give me another clue.

Thanks

in linux it is

dos2linux

Franklin

Thanks for your help.

Your script is working manually one by one at the command prompt.
But I am trying to do automatic the script is below which is not working.
For ^M character --> I am pressing < crtl v and Ctrl M> in the script.

for file in `ls /home/applmgr/test/`
do
CHECK=`cat $file | grep "^M" | wc -l`
if [ $CHECK -eq 1 ]
then
sed '/^M$/N;s/^M\N//' $file > /tmp/tempfile.tmp
mv /tmp/tempfile.tmp $file
fi
done

Please let me know if any clue or suggestion for making automatic

Thanks

Try this, beware of the ^M characters, type it as I early mentioned (with vi):

#!/bin/sh

for file in /home/applmgr/test/* ; do
  grep '^M' "$file" >/dev/null
  if [ $? == 0 ]; then
    sed '/^M$/N;s/^M\n//' "$file" > /tmp/tempfile.tmp
    mv /tmp/tempfile.tmp "$file"
  fi
done

Regards

Franklin

It worked .
Here it should be sed '/^M$/N;s/^M\n//' "$file" > /tmp/tempfile.tmp

Thanks for your help.