Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

How to set Record Separator in awk to ^M ?

465 views
Skip to first unread message

Madhusudhan M. Reddy

unread,
Mar 14, 1994, 5:58:19 PM3/14/94
to
Hello,
Would anyone let me know how to set the Record Separator to
"\^M" (i.e., CTRL-M) character. My input file has only one line which
is very large. When I open the file using the emacs editor it shows
several ^M characters, which actually ought to have been \n (newline)
characters..

Also, if the line can be broken into several lines, the line
break occuring at each of those ^M characters, then that would be fine
too.

I tried breaking the lines at each of the ^M chars. using sed.
But, sed, too, doesn't seem to understand ^M's.

Thank you for your time.

Madhusudhan Reddy


Siggy Hensel

unread,
Mar 15, 1994, 7:56:33 AM3/15/94
to
In article <2m2q6b$s...@news.tamu.edu>,

Madhusudhan M. Reddy <mre...@eemips.tamu.edu> wrote:
>Hello,
> Would anyone let me know how to set the Record Separator to
>"\^M" (i.e., CTRL-M) character. My input file has only one line which
>is very large. When I open the file using the emacs editor it shows
>several ^M characters, which actually ought to have been \n (newline)
>characters..
>
> Also, if the line can be broken into several lines, the line
>break occuring at each of those ^M characters, then that would be fine
>too.

Try the following command:

awk -F^M '{ for ( i=1 ; i<=NF ; i++ ) print $i }' < inputfile

Please be sure to enter the ^M as ( control-v control-m )

The control-v escapes the following control character. This works
with the vi editor or at the /bin/sh or /bin/ksh. If you use emacs,
it may be ( control-q control-m ) if i am right.

si...@aed-graphics.de

Jim Dailey

unread,
Mar 15, 1994, 8:47:10 AM3/15/94
to
Re re remember when mre...@eemips.tamu.edu said: (that was AWESOME wasn't it?)

Not a bad attempt for an Aggie :-). Try using tr instead. One of these
should do the trick for you:

cat junk | tr \015 \012 > | goodfile
cat junk | tr '\015' '\012' | goodfile

After this, goodfile will have newlines in place of the ^M chars.

---
Jim jda...@asic.sc.ti.com

We didn't attack you for your views. We made fun of you,
because you are an idiot. -- Thayne Forbes

J Lee Jaap

unread,
Mar 15, 1994, 10:54:55 AM3/15/94
to
jda...@asic.sc.ti.com (Jim Dailey) writes:
|>Re re remember when mre...@eemips.tamu.edu said: (that was AWESOME wasn't it?)
|>> Also, if the line can be broken into several lines, the line
|>>break occuring at each of those ^M characters, then that would be fine
|>>too.
|>>
|>> I tried breaking the lines at each of the ^M chars. using sed.
|>>But, sed, too, doesn't seem to understand ^M's.
|>
|>Not a bad attempt for an Aggie :-). Try using tr instead. One of these
|>should do the trick for you:
|>
|> cat junk | tr \015 \012 > | goodfile
|> cat junk | tr '\015' '\012' | goodfile

Woops. Try ">" instead of the second "|". Or avoiding cat altogether:

tr '\015' '\012' <junk >goodfile

--
J Lee Jaap <J.L....@LaRC.NASA.Gov> +1 804/864-2148
employed by, not necessarily speaking for, AS&M Inc,
at NASA LaRC, Hampton VA 23681-0001

mark

unread,
Mar 15, 1994, 5:53:54 PM3/15/94
to
In article <2m2q6b$s...@news.tamu.edu> mre...@eemips.tamu.edu (Madhusudhan M. Reddy) writes:
>Hello,
> Would anyone let me know how to set the Record Separator to
>"\^M" (i.e., CTRL-M) character. My input file has only one line which
>is very large. When I open the file using the emacs editor it shows
>several ^M characters, which actually ought to have been \n (newline)
>characters..
>
*sigh*
RTFM
then
BEGIN {
RS = "^M";
}
{code...}

mark


Des Costello

unread,
Mar 16, 1994, 4:58:43 AM3/16/94
to
mre...@eemips.tamu.edu (Madhusudhan M. Reddy) writes:

>Hello,
> Would anyone let me know how to set the Record Separator to
>"\^M" (i.e., CTRL-M) character.

In Aho etal, "The AWK programming language" p31 it says that
control characters can be represented by their octal number (in
much the same way as the 'tr' function in UNIX). For ^M (and a
few other characters) escape sequences have been defined. I
think it's \r (carriage return) for ^M.

Good luck,

Des
--
......o.......oo........ooo........oo0|0oo........ooo........oo.......o.......
Dr Des Costello, Department of Chemical Engineering, University of Edinburgh
phone: +44 (31) 650 5891, or e-mail to: d...@chemeng.ed.ac.uk

Charlie Stross

unread,
Mar 16, 1994, 2:16:14 PM3/16/94
to
In article <2m6l8j$4...@echt.chemeng.ed.ac.uk> d...@chemeng.ed.ac.uk
(Des Costello) writes:
> mre...@eemips.tamu.edu (Madhusudhan M. Reddy) writes:
>
> >Hello,
> > Would anyone let me know how to set the Record Separator to
> >"\^M" (i.e., CTRL-M) character.
>
> In Aho etal, "The AWK programming language" p31 it says that
> control characters can be represented by their octal number (in
> much the same way as the 'tr' function in UNIX). For ^M (and a
> few other characters) escape sequences have been defined. I
> think it's \r (carriage return) for ^M.

Correct about the octal representation. Note that this is, as far
as I know, only true for New Awk (nawk), of which gawk (GNU Awk) is
an instance. ^M is ASCII number 13, so in octal we have \015 (right?)

In fact, it would be handy when asking questions about awk if people
could try to distinguish between oawk and nawk ...


-- Charlie (who still has a soft spot for awk, despite being into perl
these days)


John Passaniti

unread,
Mar 16, 1994, 10:55:00 PM3/16/94
to
>> Would anyone let me know how to set the Record Separator to
>>"\^M" (i.e., CTRL-M) character.
>
> *sigh*
> RTFM

> BEGIN {
> RS = "^M";
> }
> {code...}

I suggest you do the same. "^M" may be a notational feature of some awk
you use, but manual I have doesn't allow that syntax.

mark

unread,
Mar 17, 1994, 6:03:07 PM3/17/94
to
I'm sorry. I just shelled out, and went over to another session, and tried it
in nawk on the SGI, nawk on the Sun, and awk on the HP, and it works in
all three of them. You did, of course, note that I was doing that in the
BEGIN, and used ctrl-v ctrl-M to enter the control-M between the quotes,
and that RS is the predefined record seperator, which may allow a few things
other variables don't (maybe).

mark

Taeke S. Tuinstra

unread,
Mar 17, 1994, 10:40:50 PM3/17/94
to

>In fact, it would be handy when asking questions about awk if people
>could try to distinguish between oawk and nawk ...

I agree, altough I don't do it al the time. Talking about different awk's,
is there anybody who has experience with the Thompson Automation, Inc
AWK compiler for dos. It's an awk compiler for dos for about $250,-. It has
the capability to generate object code that can be linked in with
Microsoft C object's.


>-- Charlie (who still has a soft spot for awk, despite being into perl
> these days)

Does it have to be the one or the other? Don't leave. The aren't to many
awk people around, so every one is needed.

Taeke

John Passaniti

unread,
Mar 21, 1994, 9:03:00 AM3/21/94
to
> From: ta...@tst.hacktic.nl (Taeke S. Tuinstra)

> I agree, altough I don't do it al the time. Talking about different
> awk's, is there anybody who has experience with the Thompson Automation,
> Inc AWK compiler for dos. It's an awk compiler for dos for about $250,-.
It
> has the capability to generate object code that can be linked in with
> Microsoft C object's.

I use (and love) Thompson Automation's awk. The only problem with it is
the numerous features they added. I'm not so much concerned about portability
in my environment, but occasionally I'll use a non-standard extension in
Thompson Automation's awk that won't work on other systems.

The ability to link in 'C' code is a thrill. The demo that comes with
the package features calls to Microsoft's graphics library, but I've used it
to access NetBIOS, mouse, and MIDI routines I've written.

I'd be happy to answer any specific questions about Thompson Automation's
awk.

>>-- Charlie (who still has a soft spot for awk, despite being into perl
>> these days)
>
> Does it have to be the one or the other? Don't leave. The aren't to many
> awk people around, so every one is needed.

My initial look at the syntax for perl leaves me cold. I should probably
pick up the O'Reily "nutshell" book, but so far I haven't found anything I
can't do (or want to do) in awk (especially Thompson Automation's version)
that perl offers.

0 new messages