Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

using 'sed & awk' book example in book won't work

Status
Not open for further replies.

desanti

Programmer
Jul 9, 2004
51
US
HI: I am using o'reilly book sed & awk and experimenting with examples in book using DOS and nawk/awk.
Data file:john robinson
koren inc.
978 common ave
boston
ma 01760
696-0987
THIS IS A MULTILINE RECORD WITH 6 FIELDS.
the book shows begin {FS = "\n";RS = ""}
{ print $1,$NF }
the output shows name and telephone#.($1,$NF).
i cannot duplicate this using the same code.i created the data file with windows notepad which shows after each field a hex(od oa)cr\lf.the output is all the fields (as if awk does'nt see BEGIN at all.if i change the cr\lf to the unix \n (oa)the output remains the same, NOT the first and last(name and telephonen#) but all fields as shown.I believe senility has set in,so stay with me.thank you.
P.S. i believe that the relationship with windows cr\lf and \n in unix may be my downfall but i do not know how to correct this.
 
Use BEGIN instead of begin.

Also, you may need

FS="\r\n"

CaKiwi
 
CaKiwi: Thanx for your reply.I did have begin in caps.also,i tried \r\n.sane result.i'll keep trying.
 
It worked fine for me on windows with the data file having crlf and using BEGIN {FS="\n";RS=""}. I tried both MKS awk and gawk.

CaKiwi
 
CaKiwi:When i worked at AT&T we used to say with UNIX,C that if only they would write clearly,because of the vagaries of the systems(that was in 1975).i never got too involved used(cobol,fortran etc.).i have an habit of dogging things to death.the long and short of it is that the -F option required -F: to work.i found that out by using the KNOPPIX cd to boot with linux.i executed GAWK and through mush knashing of teeth i found the -F option.Nowhere in the oreilly book does it show -F:.My loaded cost to my clients
(internal) was $75 an hour in 1975.i would have been fired
with the amount of time i spent on this!!!!Many thanx.
 
My copy of O'Reilly's Sed and Awk (2nd Edition) mentions the -F option on pages 21 and 144. -F: just sets the field separator to : and is the same as using FS=":" in the awk script. It should have no effect on the problem you are having.

You can download some unix utilities (including gawk) for windows at


Or get the cygwin package.

CaKiwi
 
desanti

I also have the same book - and it mentions -F on the [red]2nd page of the awk section![/red] I think you need to slow down a little. And with regard to [highlight]I wish they would write clearly[/highlight] - in one of your posts in the Perl section you refer to Perl as Pear ... maybe the problem is your end?


Kind Regards
Duncan
 
Seems like desanti has been pretty slothful since 14 Jul 2004.

vlad
+----------------------------+
| #include<disclaimer.h> |
+----------------------------+
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top