Simple help with awk 
Author Message
 Simple help with awk

Hi all from Paris !

  I got kinda a big problem !!! Transfering a text file from a mac
into my Sun, The CR is replaced by an horrible ^M !!!! (ctrl-M).

  Can soeone help me building this small awk command that replaces
the awful ^M with a proper unix CR ???

  Thanks about 1.000.000 (yes : 1.000.000) times 4 your help.

Greg.
--
------------------------------------------------------

17, r Cler                      33 1 - 44 11 22 28 (W)
75007 Paris                     33 1 - 44 11 22 42 (F)
                    http://www.*-*-*.com/ :2000/fabre



Mon, 28 Dec 1998 03:00:00 GMT  
 Simple help with awk


Quote:
>Hi all from Paris !

>  I got kinda a big problem !!! Transfering a text file from a mac
>into my Sun, The CR is replaced by an horrible ^M !!!! (ctrl-M).

>  Can soeone help me building this small awk command that replaces
>the awful ^M with a proper unix CR ???

You don't need awk for this.  Just "dos2unix" or
"tr -d '\015' <file >newfile"
(maybe "tr '\015' '\012'")
Incidentally, ^M is a CR.  Unix uses LF (^J) as the end-of-line character.

Quote:
>  Thanks about 1.000.000 (yes : 1.000.000) times 4 your help.

--

On 22 July, 1996, at 6:00 pm GMT, everyone in the world    
just START HUMMING.  Those who don't know will freak.      


Mon, 28 Dec 1998 03:00:00 GMT  
 Simple help with awk


Quote:
>   I got kinda a big problem !!! Transfering a text file from a mac
> into my Sun, The CR is replaced by an horrible ^M !!!! (ctrl-M).
>   Can soeone help me building this small awk command that replaces
> the awful ^M with a proper unix CR ???

I use sed inside a script for this task:

--------------------------------------------------------

#!/bin/ksh

# cueol - convert DOS EOL to UNIX EOL

# "^M" below is a CR character (ASCII 013) entered using
# the vi editor and the key sequence <Ctrl-V><Ctrl-M>

sed -e 's/^M$//g' < $1 > xyzxyz
mv xyzxyz $1

--------------------------------------------------------

Neil

--
 _.-_|\     Neil Muspratt                    Tel : + 61 7 3864 2146
/      QUT Technical Services Section        Fax : + 61 7 3864 1959

      v  GPO Box 2434 Brisbane Qld 4001      PGP : 2.6.2i (send email)



Tue, 29 Dec 1998 03:00:00 GMT  
 Simple help with awk


Quote:
>   I got kinda a big problem !!! Transfering a text file from a mac
> into my Sun, The CR is replaced by an horrible ^M !!!! (ctrl-M).
>   Can someone help me building this small awk command that replaces
> the awful ^M with a proper unix CR ???

If the "transfer" is via terminal emulator or communication program,
then options to adjust end-of-line may be selectable in that program.

Barring that, the "tr" program (on the Sun) can do the job of changing
all ^M (mac eol) to ^J (unix eol); using "tr" eliminates any possible
"line length limitation" of any "sed" or "awk" version, or
non-recognition (with "sed") of any "line" not terminated by ^J.

I.e. - "tr" processes any stream of bytes; it does not care about "lines",
       which is good for this purpose, because your whole file will appear
       to Unix to contain zero lines (just a stream of bytes with no eol).

I believe the command for this purpose would be:
  tr '\015' '\012' < input > output  # all ^M -> ^J

Reversing the two arguments of "tr" will perform the reverse conversion,
in case that should also prove necessary.

The above is predicated on the "mac eol" being the single character
^M (no linefeed ^J); if I got that wrong, and if you want only to
remove all ^M, with no replacement (as with MSDOS -> Unix),
then:  tr -d '\015' should do it.

-----------------------------------------------------------



Tue, 29 Dec 1998 03:00:00 GMT  
 Simple help with awk


Quote:

> >   I got kinda a big problem !!! Transfering a text file from a mac
> > into my Sun, The CR is replaced by an horrible ^M !!!! (ctrl-M).
> > [...]
> If the "transfer" is via terminal emulator or communication program,
> then options to adjust end-of-line may be selectable in that program.

     John's right. I'm guessing you're using FTP to transfer the text
file from a Macintosh PC to a Sun SPARCstation. FTP handles EOL character
translations intelligently provided you specify the correct mode: ASCII
(a.k.a. TEXT) instead of BINARY (a.k.a. IMAGE). Typically, BINARY mode is
the default, so you must explicitly set the mode to ASCII. See ftp(1) on
the SPARCstation, or click on some annoying little "Help" icon on the
Macintosh. ;-)

---
Jim Monty

Tempe, Arizona USA



Tue, 29 Dec 1998 03:00:00 GMT  
 Simple help with awk


   >   I got kinda a big problem !!! Transfering a text file from a mac
   > into my Sun, The CR is replaced by an horrible ^M !!!! (ctrl-M).

   >   Can soeone help me building this small awk command that replaces
   > the awful ^M with a proper unix CR ???

   I use sed inside a script for this task:
         ^^^
   [...]

For each problem you should use the right tool: If you have to do
(simple) character mappings (i.e. replace single characters with
typically other character, then use tr. However, if you have to map
single characters to multiple characters (e.g. unaccenting of umlaut
characters) or if you have to map multiple characters to single or
multiple characters, then use sed.

In your case it is the single character mapping problem; therefore
you'd better use tr.

Best,

Max

--
-----------------------------------------------------------------------
Bruno Maximilian Schulze           | Multilingual Theory and Technology

Tel.    +33 76 61 50 74            | 6 chemin de Maupertuis
Fax     +33 76 61 50 86            | F-38240 Meylan France
-----------------------------------------------------------------------



Fri, 01 Jan 1999 03:00:00 GMT  
 Simple help with awk

Quote:




>   > >   I got kinda a big problem !!! Transfering a text file from a mac
>   > > into my Sun, The CR is replaced by an horrible ^M !!!! (ctrl-M).
>   > > [...]
>   > If the "transfer" is via terminal emulator or communication program,
>   > then options to adjust end-of-line may be selectable in that program.
>    John's right. I'm guessing you're using FTP to transfer the text
>   file from a Macintosh PC to a Sun SPARCstation. FTP handles EOL character
>   translations intelligently provided you specify the correct mode: ASCII
>   (a.k.a. TEXT) instead of BINARY (a.k.a. IMAGE). Typically, BINARY mode is
>   the default, so you must explicitly set the mode to ASCII. See ftp(1) on
>   the SPARCstation, or click on some annoying little "Help" icon on the
>   Macintosh. ;-)
>That's new to me that the binary mode is the default. Have a look at
>ftp's man page (Solaris 2.5):
>     ascii
>          Set the representation type to network ASCII.  This  is
>          the default type.
>I have also experience with SunOS 4.1.x, HP-UX 7.x, 8.x -- and as far
>as I know all have the same default.
>I read ftp's man page a little bit further and found the cr command:
>     cr   Toggle RETURN stripping during network ASCII type  file
>          retrieval.   Records  are  denoted by a RETURN/LINEFEED
>          sequence during network ASCII type file transfer.  When
>          cr  is on (the default), RETURN characters are stripped
>          from this sequence to conform with the UNIX system sin-
>          gle  LINEFEED  record  delimiter.  Records on non-UNIX-
>          system remote hosts may contain single LINEFEED charac-
>          ters;  when  an  network  ASCII  type transfer is made,
>          these LINEFEED characters may be distinguished  from  a
>          record delimiter only when cr is off.
>However, I don't know whether this is a standard ftp command or a
>Solaris extension.

Seems to me, it is a SYSV feature.
--
Thanh Ma



Fri, 01 Jan 1999 03:00:00 GMT  
 Simple help with awk



   > >   I got kinda a big problem !!! Transfering a text file from a mac
   > > into my Sun, The CR is replaced by an horrible ^M !!!! (ctrl-M).
   > > [...]

   > If the "transfer" is via terminal emulator or communication program,
   > then options to adjust end-of-line may be selectable in that program.

        John's right. I'm guessing you're using FTP to transfer the text
   file from a Macintosh PC to a Sun SPARCstation. FTP handles EOL character
   translations intelligently provided you specify the correct mode: ASCII
   (a.k.a. TEXT) instead of BINARY (a.k.a. IMAGE). Typically, BINARY mode is
   the default, so you must explicitly set the mode to ASCII. See ftp(1) on
   the SPARCstation, or click on some annoying little "Help" icon on the
   Macintosh. ;-)

That's new to me that the binary mode is the default. Have a look at
ftp's man page (Solaris 2.5):

     ascii
          Set the representation type to network ASCII.  This  is
          the default type.

I have also experience with SunOS 4.1.x, HP-UX 7.x, 8.x -- and as far
as I know all have the same default.

I read ftp's man page a little bit further and found the cr command:

     cr   Toggle RETURN stripping during network ASCII type  file
          retrieval.   Records  are  denoted by a RETURN/LINEFEED
          sequence during network ASCII type file transfer.  When
          cr  is on (the default), RETURN characters are stripped
          from this sequence to conform with the UNIX system sin-
          gle  LINEFEED  record  delimiter.  Records on non-UNIX-
          system remote hosts may contain single LINEFEED charac-
          ters;  when  an  network  ASCII  type transfer is made,
          these LINEFEED characters may be distinguished  from  a
          record delimiter only when cr is off.

However, I don't know whether this is a standard ftp command or a
Solaris extension.

Best,

Max
--
-----------------------------------------------------------------------
Bruno Maximilian Schulze           | Multilingual Theory and Technology

Tel.    +33 76 61 50 74            | 6 chemin de Maupertuis
Fax     +33 76 61 50 86            | F-38240 Meylan France
-----------------------------------------------------------------------



Fri, 01 Jan 1999 03:00:00 GMT  
 
 [ 8 post ] 

 Relevant Pages 

1. Very simple awk for a simple user

2. Help with A simple awk script.

3. awk:Simpler question: But critical ; please help

4. Need help to write a simple awk script

5. Need help with simple awk script

6. Arrays in awk/awk help please!

7. Help with Awk, totally new to AWK programing

8. AWK newbie is looking for a AWK help with his 1st program

9. Simple task-not simple for Dummy, Help

10. Simple awk question

11. A very simple question on SED or AWK for a GURU, and an enjoyable problem

12. A simple question regarding shell scripts and awk

 

 
Powered by phpBB® Forum Software