Hot to get rid of control chars ?

Hot to get rid of control chars ?

Post by Murty Adav » Fri, 05 Oct 2001 09:18:29



Hi,

I would like  to  get rid of the occurences of ^M^J charachter combination
(carriage return & line feed combination)in my file.
That is I want to get rid of  all  the  occurences of   \015\012

For Example, the following file

1234^M
456
^M
789

should becom

123456
789

Any help is greatly appreciated.
Thanks in advance,,,,,Murty

 
 
 

Hot to get rid of control chars ?

Post by Chris F.A. Johnso » Fri, 05 Oct 2001 09:56:32



> Hi,

> I would like  to  get rid of the occurences of ^M^J charachter combination
> (carriage return & line feed combination)in my file.
> That is I want to get rid of  all  the  occurences of   \015\012

> For Example, the following file

> 1234^M
> 456
> ^M
> 789

> should becom

> 123456
> 789

tr -d '\015' < FILE > NEWFILE

This gets rid off all ^M characters in the file; if you want to keep those
that are not at the end of a line, check the archives; this was discussed
recently: http://groups.google.com/groups?hl=en&group=comp.unix.shell

--
    Chris F.A. Johnson                        http://cfaj.freeshell.org
    ===================================================================
    My code (if any) in this post is copyright 2001, Chris F.A. Johnson
    and may be copied under the terms of the GNU General Public License

 
 
 

Hot to get rid of control chars ?

Post by Stephane Chazel » Fri, 05 Oct 2001 15:18:47



> Hi,

> I would like  to  get rid of the occurences of ^M^J charachter combination
> (carriage return & line feed combination)in my file.
> That is I want to get rid of  all  the  occurences of   \015\012

CTRL_M=`printf '\r'`
sed -e '
  :1
  /'"$CTRL_M"'$/{
    s///
    $!N
    s/\n//
    t1
  }'

It will also remove a trailing ^M on the last line. So, if your file
ends with '^M^J', it will be OK, if your file ends with '^M', either
your sed really doesn't like it and it will delete this line, either
your sed can handle it and the trailing ^M will be removed. But a text
file is supposed to end with ^J.

--
Stphane

 
 
 

Hot to get rid of control chars ?

Post by laura fairhe » Sat, 06 Oct 2001 11:06:27



>Hi,

>I would like  to  get rid of the occurences of ^M^J charachter combination
>(carriage return & line feed combination)in my file.
>That is I want to get rid of  all  the  occurences of   \015\012

>For Example, the following file

>1234^M
>456
>^M
>789

>should becom

>123456
>789

>Any help is greatly appreciated.
>Thanks in advance,,,,,Murty

use tr, 'man tr'

to delete characters use the '-d' switch;

tr -d '\15\12' <sourcefilename >destinationfilename

that will put the whole file all together in one line.
the line should at least be terminated with a single LF;

echo >>destinationfilename

if you just want to remove the CR characters (to get
a UNIX compatible text file with no ^M's showing up);

tr -d '\15' <sourcefilename >destinationfilename

BTW: I have a port of BSD 'tr' for MSDOS available on my
     website. See the TOOLS page.

byefrom

--
: ${L:-aura} # http://lf.8k.com:80
:            # http://lf.1accesshost.com

- Show quoted text -

 
 
 

1. How to get rid of tty control chars?

Hi,

        We have been looking for a filter or any kind of program in order
        to get rid of the tty control character that appear when you
        try to log a session by using the "script" command.

        Does anybody out there have solved that problem?

                Thanks a lot.

Josep R. Herrero
Dpt. Arquitectura de Computadors
Universitat Politecnica de Catalunya
Barcelona

           ... Let's keep our planet as it used to be ...
                  ... Reduce, Reuse, Recycle ...

2. veb server and cpu%

3. get rid of control char in text file

4. -Can- Red Hat EL 3 run Ipsec-Tools-4.0?

5. Getting RID of Access Control Lists (ACLs)

6. ut_host under Solaris

7. char *strcasestr(char *haystack, char *needle) a simple case independent strstr()

8. Does Linux support a Sony CD-ROM on a Pro AudioSpectrum 16?

9. How do I get rid of vt100 graphics chars?

10. how to get rid of end of line char by using scripts

11. Non-printable chars in filenames: how do you get rid of them?

12. how to get rid of xmms in KDE control bar

13. How Hot is too hot?