Re: Problem with sed and awk

2004-03-01 Thread Jan Grant
On Thu, 26 Feb 2004, [iso-8859-2] Roubí?ek Zden?k (T-Systems PragoNet) wrote:

>
>  Hello questions
>
>  Any idea what I am missing?
>
> >cat test
> 1;1
> 2;2
> >awk -F ';' '{print $1}'
> 1
> 2
> >awk -F ' FS=";" {print $1}'
> 1;1
> 2
> >

The FS=";" is a pattern expression that is used to match the first line
of input, after it has already been split into fields. It evaluates true
so the block it guards is always run. After the first line has been
dealt with, future lines will be split using the new FS setting. As
another poster supplied, slap the FS setting in a BEGIN-guarded block.

-- 
jan grant, ILRT, University of Bristol. http://www.ilrt.bris.ac.uk/
Tel +44(0)117 9287088 Fax +44 (0)117 9287112 http://ioctl.org/jan/
If it's broken really badly - don't fix it either.
___
[EMAIL PROTECTED] mailing list
http://lists.freebsd.org/mailman/listinfo/freebsd-questions
To unsubscribe, send any mail to "[EMAIL PROTECTED]"


Problem with sed and awk

2004-02-26 Thread Roubíček Zdeněk (T-Systems PragoNet)

 Hello questions

 Any idea what I am missing?

>cat test
1;1
2;2
>awk -F ';' '{print $1}'
1
2
>awk -F ' FS=";" {print $1}'
1;1
2
>

awk --version
GNU Awk 3.0.6
Copyright (C) 1989, 1991-2000 Free Software Foundation.

uname -rs
FreeBSD 4.9-STABLE

Regards, rouba

 PS: Please cc: since I am not subscribed to this list.
___
[EMAIL PROTECTED] mailing list
http://lists.freebsd.org/mailman/listinfo/freebsd-questions
To unsubscribe, send any mail to "[EMAIL PROTECTED]"


Re: Problem with sed and awk

2004-02-26 Thread Doug Poland

Roubíèek Zdenìk (T-Systems PragoNet) said:
>
>  Any idea what I am missing?
>
>>cat test
> 1;1
> 2;2
>>awk -F ';' '{print $1}'
> 1
> 2
>>awk -F ' FS=";" {print $1}'
> 1;1
> 2
>>
>

awk 'BEGIN{FS=";"}{print $1}' test


-- 
Regards,
Doug

___
[EMAIL PROTECTED] mailing list
http://lists.freebsd.org/mailman/listinfo/freebsd-questions
To unsubscribe, send any mail to "[EMAIL PROTECTED]"


Re: Problem with sed and awk

2004-02-26 Thread Warren Block
On Thu, 26 Feb 2004, [iso-8859-2] Roubíèek Zdenìk (T-Systems PragoNet) wrote:

>  Any idea what I am missing?

You don't say what you are expecting these awk samples to do...

> >cat test
   
There is a command called test, so you should not use that name for test
files.

> 1;1
> 2;2
> >awk -F ';' '{print $1}'
> 1
> 2

This is doing what you've told it.  The field separator is ; and it
prints the first field on each line (assuming you are actually running
it on the 'test' file--the command as shown won't do it).

> >awk -F ' FS=";" {print $1}'
> 1;1
> 2

Don't use the -F option if you are setting the field separator inside
the code.

-Warren Block * Rapid City, South Dakota USA
___
[EMAIL PROTECTED] mailing list
http://lists.freebsd.org/mailman/listinfo/freebsd-questions
To unsubscribe, send any mail to "[EMAIL PROTECTED]"


RE: Problem with sed and awk - SOLVED

2004-02-26 Thread Roubíček Zdeněk (T-Systems PragoNet)

 Sorry for not very clearly formulated question. I wrote those commands by hand and 
obviously with lot of errors.

> 
> > >awk -F ' FS=";" {print $1}'
> > 1;1
> > 2
> 
> Don't use the -F option if you are setting the field separator inside
> the code.
> 

 This was a mistake. 

The problem is solved by 
awk 'BEGIN{FS=";"}{print $1}' testfile 

as suggested by Dough Poland. 

Thx for the replies.

 r.

Zdenek Roubicek

Department of Network Management
T-Systems PragoNet, a.s.
Na Pankráci 1685/19,140 21 Prague 4
Phone : +420 2 3609 9615
Fax   : +420 2 3609 
E-Mail: [EMAIL PROTECTED]

 
___
[EMAIL PROTECTED] mailing list
http://lists.freebsd.org/mailman/listinfo/freebsd-questions
To unsubscribe, send any mail to "[EMAIL PROTECTED]"