For Programmers: Free Programming Magazines  


Home > Archive > AWK > December 2006 > Confusing awk behaviour?!









You are viewing an archived Text-only version of the thread. To view this thread in it's original format and/or if you want to reply to this thread please [click here]

 

Author Confusing awk behaviour?!
janvdberg@gmail.com

2006-12-21, 3:57 am

Please regard the following (this is the actual line that doesn't work;
you can copy/paste it and test for yourself):

lswsuper:/# cat test
1 09:16:05 12.45.63.22 www.test.nl: www.test.nl 13.23.20.14 - -
[20/Dec/2006:09:16:05 +0100] "GET / HTTP/1.1" 200 5214
"http://www.bla.nl/" "Mozilla/4.0 (compatible; MSIE 6.0; Windows NT
5.1; SV1; .NET CLR 1.0.3705; .NET CLR 1.1.4322; Media Center PC 4.0;
..NET CLR 2.0.50727; InfoPath.1)"
lswsuper:/# awk '{print
$7,$8,$9,$10,$11,$12,$13,$14,$15,$16,$17
,$18,$19,$20,$21,$22,$23,$24,$25,$26,$27
,$28,$28,$29,$30,$31,$32,$33,$35,$36,$37
,$40}'
test
- - [20/Dec/2006:09:16:05 +0100] "GET / HTTP/1.1" 200 5214
"http://www.bla.nl/" "Mozilla/4.0 (compatible; MSIE 6.0; Windows NT
5.1; SV1; .NET CLR 1.0.3705; .NET .NET CLR 1.1.4322; Media Center PC
..NET CLR 2.0.50727;

As you can see the last field ("InfoPath") is cut off by awk: it should
however be 'shown'.

lswsuper:/# cat test
1 2 09:16:05 12.45.63.22 www.test.nl: www.test.nl 13.23.20.14 - -
[20/Dec/2006:09:16:05 +0100] "GET / HTTP/1.1" 200 5214
"http://www.bla.nl/" "Mozilla/4.0 (compatible; MSIE 6.0; Windows NT
5.1; SV1; .NET CLR 1.0.3705; .NET CLR 1.1.4322; Media Center PC 4.0;
..NET CLR 2.0.50727; InfoPath.1)"
lswsuper:/# awk '{print
$7,$8,$9,$10,$11,$12,$13,$14,$15,$16,$17
,$18,$19,$20,$21,$22,$23,$24,$25,$26,$27
,$28,$28,$29,$30,$31,$32,$33,$35,$36,$37
,$40}'
test
13.23.20.14 - - [20/Dec/2006:09:16:05 +0100] "GET / HTTP/1.1" 200 5214
"http://www.bla.nl/" "Mozilla/4.0 (compatible; MSIE 6.0; Windows NT
5.1; SV1; .NET CLR 1.0.3705; 1.0.3705; .NET CLR 1.1.4322; Media Center
4.0; .NET CLR

As you can see I've an extra '2' word (1 2) at the beginning the line
however this resulted in the last 2 fields being cut off?!

lswsuper:/# cat test
1 2 3 09:16:05 12.45.63.22 www.test.nl: www.test.nl 13.23.20.14 - -
[20/Dec/2006:09:16:05 +0100] "GET / HTTP/1.1" 200 5214
"http://www.bla.nl/" "Mozilla/4.0 (compatible; MSIE 6.0; Windows NT
5.1; SV1; .NET CLR 1.0.3705; .NET CLR 1.1.4322; Media Center PC 4.0;
..NET CLR 2.0.50727; InfoPath.1)"
lswsuper:/# awk '{print
$7,$8,$9,$10,$11,$12,$13,$14,$15,$16,$17
,$18,$19,$20,$21,$22,$23,$24,$25,$26,$27
,$28,$28,$29,$30,$31,$32,$33,$35,$36,$37
,$40}'
test
www.test.nl 13.23.20.14 - - [20/Dec/2006:09:16:05 +0100] "GET /
HTTP/1.1" 200 5214 "http://www.bla.nl/" "Mozilla/4.0 (compatible; MSIE
6.0; Windows NT 5.1; SV1; .NET CLR CLR 1.0.3705; .NET CLR 1.1.4322;
Media PC 4.0; .NET InfoPath.1)"

Now I've added two extra words (1 2 3) at the beginning of the line and
now awk does what I want it to do?!?

I can't explain this; who can?
GNU bash, version 2.05b.0(1)-release
GNU Awk 3.1.4

news.t-online.de

2006-12-21, 7:57 am


You have to find out how many
seperators your test files has.
First you have to find out whether
your test file with one line has double spaces.
If, then replace them by a single space.
Then you have to find out
whether there is a space at the beginning
or end of the line, then remove them.
Then you lswsuper:/# tr -d -c " " < test | wc -c
This then gives you an amount of spaces in the file,
you add 1 on it, and this is the number of fields.
If it is less than what you expect,
then this is a problem of your expectation,
If it is equal to your expectation try this with awk again.
That what I copy from your message
just has 38 Fields.
If you insert 1 2, then it has 40.









janvdberg@gmail.com wrote:
> Please regard the following (this is the actual line that doesn't work;
> you can copy/paste it and test for yourself):
>
> lswsuper:/# cat test
> 1 09:16:05 12.45.63.22 www.test.nl: www.test.nl 13.23.20.14 - -
> [20/Dec/2006:09:16:05 +0100] "GET / HTTP/1.1" 200 5214
> "http://www.bla.nl/" "Mozilla/4.0 (compatible; MSIE 6.0; Windows NT
> 5.1; SV1; .NET CLR 1.0.3705; .NET CLR 1.1.4322; Media Center PC 4.0;
> .NET CLR 2.0.50727; InfoPath.1)"
> lswsuper:/# awk '{print
> $7,$8,$9,$10,$11,$12,$13,$14,$15,$16,$17
,$18,$19,$20,$21,$22,$23,$24,$25,$26,$27
,$28,$28,$29,$30,$31,$32,$33,$35,$36,$37
,$40}'
> test
> - - [20/Dec/2006:09:16:05 +0100] "GET / HTTP/1.1" 200 5214
> "http://www.bla.nl/" "Mozilla/4.0 (compatible; MSIE 6.0; Windows NT
> 5.1; SV1; .NET CLR 1.0.3705; .NET .NET CLR 1.1.4322; Media Center PC
> .NET CLR 2.0.50727;
>
> As you can see the last field ("InfoPath") is cut off by awk: it should
> however be 'shown'.
>
> lswsuper:/# cat test
> 1 2 09:16:05 12.45.63.22 www.test.nl: www.test.nl 13.23.20.14 - -
> [20/Dec/2006:09:16:05 +0100] "GET / HTTP/1.1" 200 5214
> "http://www.bla.nl/" "Mozilla/4.0 (compatible; MSIE 6.0; Windows NT
> 5.1; SV1; .NET CLR 1.0.3705; .NET CLR 1.1.4322; Media Center PC 4.0;
> .NET CLR 2.0.50727; InfoPath.1)"
> lswsuper:/# awk '{print
> $7,$8,$9,$10,$11,$12,$13,$14,$15,$16,$17
,$18,$19,$20,$21,$22,$23,$24,$25,$26,$27
,$28,$28,$29,$30,$31,$32,$33,$35,$36,$37
,$40}'
> test
> 13.23.20.14 - - [20/Dec/2006:09:16:05 +0100] "GET / HTTP/1.1" 200 5214
> "http://www.bla.nl/" "Mozilla/4.0 (compatible; MSIE 6.0; Windows NT
> 5.1; SV1; .NET CLR 1.0.3705; 1.0.3705; .NET CLR 1.1.4322; Media Center
> 4.0; .NET CLR
>
> As you can see I've an extra '2' word (1 2) at the beginning the line
> however this resulted in the last 2 fields being cut off?!
>
> lswsuper:/# cat test
> 1 2 3 09:16:05 12.45.63.22 www.test.nl: www.test.nl 13.23.20.14 - -
> [20/Dec/2006:09:16:05 +0100] "GET / HTTP/1.1" 200 5214
> "http://www.bla.nl/" "Mozilla/4.0 (compatible; MSIE 6.0; Windows NT
> 5.1; SV1; .NET CLR 1.0.3705; .NET CLR 1.1.4322; Media Center PC 4.0;
> .NET CLR 2.0.50727; InfoPath.1)"
> lswsuper:/# awk '{print
> $7,$8,$9,$10,$11,$12,$13,$14,$15,$16,$17
,$18,$19,$20,$21,$22,$23,$24,$25,$26,$27
,$28,$28,$29,$30,$31,$32,$33,$35,$36,$37
,$40}'
> test
> www.test.nl 13.23.20.14 - - [20/Dec/2006:09:16:05 +0100] "GET /
> HTTP/1.1" 200 5214 "http://www.bla.nl/" "Mozilla/4.0 (compatible; MSIE
> 6.0; Windows NT 5.1; SV1; .NET CLR CLR 1.0.3705; .NET CLR 1.1.4322;
> Media PC 4.0; .NET InfoPath.1)"
>
> Now I've added two extra words (1 2 3) at the beginning of the line and
> now awk does what I want it to do?!?
>
> I can't explain this; who can?
> GNU bash, version 2.05b.0(1)-release
> GNU Awk 3.1.4
>

Janis Papanagnou

2006-12-21, 7:57 am

janvdberg@gmail.com wrote:
> Please regard the following (this is the actual line that doesn't work;
> you can copy/paste it and test for yourself):
>
> lswsuper:/# cat test
> 1 09:16:05 12.45.63.22 www.test.nl: www.test.nl 13.23.20.14 - -
> [20/Dec/2006:09:16:05 +0100] "GET / HTTP/1.1" 200 5214
> "http://www.bla.nl/" "Mozilla/4.0 (compatible; MSIE 6.0; Windows NT
> 5.1; SV1; .NET CLR 1.0.3705; .NET CLR 1.1.4322; Media Center PC 4.0;
> .NET CLR 2.0.50727; InfoPath.1)"
> lswsuper:/# awk '{print
> $7,$8,$9,$10,$11,$12,$13,$14,$15,$16,$17
,$18,$19,$20,$21,$22,$23,$24,$25,$26,$27
,$28,$28,$29,$30,$31,$32,$33,$35,$36,$37
,$40}'
> test
> - - [20/Dec/2006:09:16:05 +0100] "GET / HTTP/1.1" 200 5214
> "http://www.bla.nl/" "Mozilla/4.0 (compatible; MSIE 6.0; Windows NT
> 5.1; SV1; .NET CLR 1.0.3705; .NET .NET CLR 1.1.4322; Media Center PC
> .NET CLR 2.0.50727;
>
> As you can see the last field ("InfoPath") is cut off by awk: it should
> however be 'shown'.
>
> lswsuper:/# cat test
> 1 2 09:16:05 12.45.63.22 www.test.nl: www.test.nl 13.23.20.14 - -
> [20/Dec/2006:09:16:05 +0100] "GET / HTTP/1.1" 200 5214
> "http://www.bla.nl/" "Mozilla/4.0 (compatible; MSIE 6.0; Windows NT
> 5.1; SV1; .NET CLR 1.0.3705; .NET CLR 1.1.4322; Media Center PC 4.0;
> .NET CLR 2.0.50727; InfoPath.1)"
> lswsuper:/# awk '{print
> $7,$8,$9,$10,$11,$12,$13,$14,$15,$16,$17
,$18,$19,$20,$21,$22,$23,$24,$25,$26,$27
,$28,$28,$29,$30,$31,$32,$33,$35,$36,$37
,$40}'
> test
> 13.23.20.14 - - [20/Dec/2006:09:16:05 +0100] "GET / HTTP/1.1" 200 5214
> "http://www.bla.nl/" "Mozilla/4.0 (compatible; MSIE 6.0; Windows NT
> 5.1; SV1; .NET CLR 1.0.3705; 1.0.3705; .NET CLR 1.1.4322; Media Center
> 4.0; .NET CLR
>
> As you can see I've an extra '2' word (1 2) at the beginning the line
> however this resulted in the last 2 fields being cut off?!
>
> lswsuper:/# cat test
> 1 2 3 09:16:05 12.45.63.22 www.test.nl: www.test.nl 13.23.20.14 - -
> [20/Dec/2006:09:16:05 +0100] "GET / HTTP/1.1" 200 5214
> "http://www.bla.nl/" "Mozilla/4.0 (compatible; MSIE 6.0; Windows NT
> 5.1; SV1; .NET CLR 1.0.3705; .NET CLR 1.1.4322; Media Center PC 4.0;
> .NET CLR 2.0.50727; InfoPath.1)"
> lswsuper:/# awk '{print
> $7,$8,$9,$10,$11,$12,$13,$14,$15,$16,$17
,$18,$19,$20,$21,$22,$23,$24,$25,$26,$27
,$28,$28,$29,$30,$31,$32,$33,$35,$36,$37
,$40}'
> test
> www.test.nl 13.23.20.14 - - [20/Dec/2006:09:16:05 +0100] "GET /
> HTTP/1.1" 200 5214 "http://www.bla.nl/" "Mozilla/4.0 (compatible; MSIE
> 6.0; Windows NT 5.1; SV1; .NET CLR CLR 1.0.3705; .NET CLR 1.1.4322;
> Media PC 4.0; .NET InfoPath.1)"
>
> Now I've added two extra words (1 2 3) at the beginning of the line and
> now awk does what I want it to do?!?
>
> I can't explain this; who can?
> GNU bash, version 2.05b.0(1)-release
> GNU Awk 3.1.4
>


I can't read your data that is wrapped around many lines. If you have
problems with the number of fields run this program on your data...

awk '{print NF}' your-test-data

....and see whether all the lines have the necessary number of fields.

Janis
janvdberg@gmail.com

2006-12-21, 7:57 am

Hi guys,

thanks for the replys. However the focus is not on how much
fields/seperators I use because this is not an issue. I have tested
this by enlarging my awk statement:
awk ' { print
$7,$8,$9,$10,$11,$12,$13,$14,$15,$16,$17
,$18,$19,$20,$21,$22,$23,$24,$25,$26,$27
,$28,$29,$30,$31,$32,$33,$35,$36,$37,$40
,$41,$42,$43,$44,$45,$46,$47,$48,$49,$50
,$51,$52,$53,$54}'
test

I can go to $100 this doesnt make difference (the line is only 39 or so
fields (depending on whether I added words), so $54 would be plenty). I
dont have any double spaces or other seperators.

The problem is that a smaller file gets cut off earlier (1) than a
larger file (1 2 3) with the same awk statement. This is weird; because
one would expect a bigger file to get cut off earlier (or not at all
with my print statement going up to $54)
My line has n spaces and n+1 fields. I have tested this with the exact
lines from this post in different terminals. If you'd be so kind you
could test it too and see for yourself.

Janis Papanagnou wrote:
> janvdberg@gmail.com wrote:
>
> I can't read your data that is wrapped around many lines. If you have
> problems with the number of fields run this program on your data...
>
> awk '{print NF}' your-test-data
>
> ...and see whether all the lines have the necessary number of fields.
>
> Janis


janvdberg@gmail.com

2006-12-21, 7:57 am

Hi guys,

thanks for the replys. However the focus is not on how much
fields/seperators I use because this is not an issue. I have tested
this by enlarging my awk statement:
awk ' { print
$7,$8,$9,$10,$11,$12,$13,$14,$15,$16,$17
,$18,$19,$20,$21,$22,$23,$24,$25,$26,$27
,$28,$29,$30,$31,$32,$33,$35,$36,$37,$40
,$41,$42,$43,$44,$45,$46,$47,$48,$49,$50
,$51,$52,$53,$54}'
test

I can go to $100 this doesnt make difference (the line is only 39 or so
fields (depending on whether I added words), so $54 would be plenty). I
dont have any double spaces or other seperators.

The problem is that a smaller file gets cut off earlier (1) than a
larger file (1 2 3) with the same awk statement. This is weird; because
one would expect a bigger file to get cut off earlier (or not at all
with my print statement going up to $54)
My line has n spaces and n+1 fields. I have tested this with the exact
lines from this post in different terminals. If you'd be so kind you
could test it too and see for yourself.

Janis Papanagnou wrote:
> janvdberg@gmail.com wrote:
>
> I can't read your data that is wrapped around many lines. If you have
> problems with the number of fields run this program on your data...
>
> awk '{print NF}' your-test-data
>
> ...and see whether all the lines have the necessary number of fields.
>
> Janis


Vassilis

2006-12-21, 7:57 am


=CF/=C7 janvdberg@gmail.com =DD=E3=F1=E1=F8=E5:
> Please regard the following (this is the actual line that doesn't work;
> you can copy/paste it and test for yourself):
>
> lswsuper:/# cat test
> 1 09:16:05 12.45.63.22 www.test.nl: www.test.nl 13.23.20.14 - -
> [20/Dec/2006:09:16:05 +0100] "GET / HTTP/1.1" 200 5214
> "http://www.bla.nl/" "Mozilla/4.0 (compatible; MSIE 6.0; Windows NT
> 5.1; SV1; .NET CLR 1.0.3705; .NET CLR 1.1.4322; Media Center PC 4.0;
> .NET CLR 2.0.50727; InfoPath.1)"
> lswsuper:/# awk '{print
> $7,$8,$9,$10,$11,$12,$13,$14,$15,$16,$17
,$18,$19,$20,$21,$22,$23,$24,$25,=

$26,$27,$28,$28,$29,$30,$31,$32,$33,$35,
$36,$37,$40}'
> test
> - - [20/Dec/2006:09:16:05 +0100] "GET / HTTP/1.1" 200 5214
> "http://www.bla.nl/" "Mozilla/4.0 (compatible; MSIE 6.0; Windows NT
> 5.1; SV1; .NET CLR 1.0.3705; .NET .NET CLR 1.1.4322; Media Center PC
> .NET CLR 2.0.50727;
>
> As you can see the last field ("InfoPath") is cut off by awk: it should
> however be 'shown'.


No, it shouldn't be shown. I think you missed something in counting:
~$ awk '{ print NR, NF }' test
1 38

Last field is the 38th and you ask to print
..=2E. $35,$36,$37,$40}' test

> lswsuper:/# cat test
> 1 2 09:16:05 12.45.63.22 www.test.nl: www.test.nl 13.23.20.14 - -
> [20/Dec/2006:09:16:05 +0100] "GET / HTTP/1.1" 200 5214
> "http://www.bla.nl/" "Mozilla/4.0 (compatible; MSIE 6.0; Windows NT
> 5.1; SV1; .NET CLR 1.0.3705; .NET CLR 1.1.4322; Media Center PC 4.0;
> .NET CLR 2.0.50727; InfoPath.1)"
> lswsuper:/# awk '{print
> $7,$8,$9,$10,$11,$12,$13,$14,$15,$16,$17
,$18,$19,$20,$21,$22,$23,$24,$25,=

$26,$27,$28,$28,$29,$30,$31,$32,$33,$35,
$36,$37,$40}'
> test
> 13.23.20.14 - - [20/Dec/2006:09:16:05 +0100] "GET / HTTP/1.1" 200 5214
> "http://www.bla.nl/" "Mozilla/4.0 (compatible; MSIE 6.0; Windows NT
> 5.1; SV1; .NET CLR 1.0.3705; 1.0.3705; .NET CLR 1.1.4322; Media Center
> 4.0; .NET CLR
>
> As you can see I've an extra '2' word (1 2) at the beginning the line
> however this resulted in the last 2 fields being cut off?!
>
> lswsuper:/# cat test
> 1 2 3 09:16:05 12.45.63.22 www.test.nl: www.test.nl 13.23.20.14 - -
> [20/Dec/2006:09:16:05 +0100] "GET / HTTP/1.1" 200 5214
> "http://www.bla.nl/" "Mozilla/4.0 (compatible; MSIE 6.0; Windows NT
> 5.1; SV1; .NET CLR 1.0.3705; .NET CLR 1.1.4322; Media Center PC 4.0;
> .NET CLR 2.0.50727; InfoPath.1)"
> lswsuper:/# awk '{print
> $7,$8,$9,$10,$11,$12,$13,$14,$15,$16,$17
,$18,$19,$20,$21,$22,$23,$24,$25,=

$26,$27,$28,$28,$29,$30,$31,$32,$33,$35,
$36,$37,$40}'
> test
> www.test.nl 13.23.20.14 - - [20/Dec/2006:09:16:05 +0100] "GET /
> HTTP/1.1" 200 5214 "http://www.bla.nl/" "Mozilla/4.0 (compatible; MSIE
> 6.0; Windows NT 5.1; SV1; .NET CLR CLR 1.0.3705; .NET CLR 1.1.4322;
> Media PC 4.0; .NET InfoPath.1)"
>
> Now I've added two extra words (1 2 3) at the beginning of the line and
> now awk does what I want it to do?!?
>
> I can't explain this; who can?
> GNU bash, version 2.05b.0(1)-release
> GNU Awk 3.1.4


janvdberg@gmail.com

2006-12-21, 7:57 am

You are so right.

..=2E..

THANKS for the fresh input, I was staring myself blind on this.

It seems something that something I asked a year ago in this very same
group has come an bitten me in the ass (since I have longer loglines
now):

http://groups.google.com/group/comp...read/b229cc7f6=
1ecafe9/


Vassilis wrote:[color=darkred]
> =CF/=C7 janvdberg@gmail.com =DD=E3=F1=E1=F8=E5:
5,$26,$27,$28,$28,$29,$30,$31,$32,$33,$3
5,$36,$37,$40}'[color=darkred]
>
> No, it shouldn't be shown. I think you missed something in counting:
> ~$ awk '{ print NR, NF }' test
> 1 38
>
> Last field is the 38th and you ask to print
> ... $35,$36,$37,$40}' test
>
5,$26,$27,$28,$28,$29,$30,$31,$32,$33,$3
5,$36,$37,$40}'[color=darkred]
5,$26,$27,$28,$28,$29,$30,$31,$32,$33,$3
5,$36,$37,$40}'[color=darkred]

Ed Morton

2006-12-21, 6:57 pm

janvdberg@gmail.com wrote:

[ please don't top-post, fixed below ]

> Janis Papanagnou wrote:
>

No, it shouldn't. You didn't ask awk to print the 38th (final) field.
[color=darkred]

OK, so you added a field ("2") to the start of the line so now all the
fields are shifted by 1 resulting in the last originally output field
now not getting printed. What's the problem?
[color=darkred]

Now that the line has 40 fields, you can print the 40th field. Not a
huge surprise.
[color=darkred]
>
> Hi guys,
>
> thanks for the replys. However the focus is not on how much
> fields/seperators I use because this is not an issue. I have tested


Yes, it is. You think you have 40 fields in your original input file,
but you don't.

> this by enlarging my awk statement:
> awk ' { print
> $7,$8,$9,$10,$11,$12,$13,$14,$15,$16,$17
,$18,$19,$20,$21,$22,$23,$24,$25,$26,$27
,$28,$29,$30,$31,$32,$33,$35,$36,$37,$40
,$41,$42,$43,$44,$45,$46,$47,$48,$49,$50
,$51,$52,$53,$54}'
> test
>
> I can go to $100 this doesnt make difference (the line is only 39 or so
> fields (depending on whether I added words), so $54 would be plenty). I
> dont have any double spaces or other seperators.


Of course it doesn't make a difference. You're problem is you're trying
to print a 40th field that doesn't exist so trying to print any field
number beyond that isn't going to print anything but field separators.

Double spaces don't make any difference - by default the FS of " " tells
awk to treat contiguous chains of white space as a single separator.

> The problem is that a smaller file gets cut off earlier (1) than a
> larger file (1 2 3) with the same awk statement. This is weird; because
> one would expect a bigger file to get cut off earlier (or not at all
> with my print statement going up to $54)


You end our awk script by printing fields 37 then 40. By adding fields
you're pushing your original 38th (final) field (originally not printed)
into the 40th position so it does get printed.

> My line has n spaces and n+1 fields. I have tested this with the exact
> lines from this post in different terminals. If you'd be so kind you
> could test it too and see for yourself.


Run this script on your input file:

awk '{for (i=1;i<=NF;i++) printf "%2d: <%s>\n",i,$i}' test

It'll help you see what your fields are.

Ed.
janvdberg@gmail.com

2006-12-21, 6:57 pm

Hi Ed,

thank you for your thorough explanation, I already figured out my
problem, nonetheless I greatly appreciate your reply. What you say is
all true.
Sorry for the top-post (I'm using Google groups; maybe that why I
toppost).

Regards,

Jan
Ed Morton wrote:
> janvdberg@gmail.com wrote:
>
> [ please don't top-post, fixed below ]
>
>
> No, it shouldn't. You didn't ask awk to print the 38th (final) field.
>
>
> OK, so you added a field ("2") to the start of the line so now all the
> fields are shifted by 1 resulting in the last originally output field
> now not getting printed. What's the problem?
>
>
> Now that the line has 40 fields, you can print the 40th field. Not a
> huge surprise.
>
>
> Yes, it is. You think you have 40 fields in your original input file,
> but you don't.
>
>
> Of course it doesn't make a difference. You're problem is you're trying
> to print a 40th field that doesn't exist so trying to print any field
> number beyond that isn't going to print anything but field separators.
>
> Double spaces don't make any difference - by default the FS of " " tells
> awk to treat contiguous chains of white space as a single separator.
>
>
> You end our awk script by printing fields 37 then 40. By adding fields
> you're pushing your original 38th (final) field (originally not printed)
> into the 40th position so it does get printed.
>
>
> Run this script on your input file:
>
> awk '{for (i=1;i<=NF;i++) printf "%2d: <%s>\n",i,$i}' test
>
> It'll help you see what your fields are.
>
> Ed.


Janis

2006-12-21, 6:57 pm

janvdberg@gmail.com wrote:
> Hi Ed,
>
> thank you for your thorough explanation, I already figured out my
> problem, nonetheless I greatly appreciate your reply. What you say is
> all true.
> Sorry for the top-post (I'm using Google groups; maybe that why I
> toppost).


No; you top-post because _you_ put your text above the quoted text.

Please read http://cfaj.freeshell.org/google/ and stop top-posting.

Janis

This posting is also done through google and not top-posted as you see.

news.t-online.de

2006-12-21, 6:57 pm

As I said, your file has 38 Fields,
as far as I can see it from your news wrapped
file example.
There is a gap in your awk command,
$38,$39 is missing.
If you add two fields
your last field slips into $40,
and it's printed.
$31,$32,$33,$35,$36,$37,$40,$41,
On pos 38 and 39 it is not printed.
$34 is missing as well, if not
left out on purpose
Sponsored Links







Also available: Server administration forum archive | Web Design forum archive | Software forum archive | Hardware reviews archive

Copyright 2008 codecomments.com