On Wed, 20 Nov 2013, Kathryn Hogg wrote:
> On 2013-11-20 00:16, Mike Miller wrote:
>
>> On Tue, 19 Nov 2013, Kathryn Hogg wrote:
>
> BEGIN is a special pattern that is applied once before any lines are
> read. My second line doesn't have a pattern so its applied to all lines.
>
>>
>> echo "a;2; 3;4;5 ;abcdefghijk;7;8;9" | awk -F';' 'BEGIN { OFS=";"}
>> {$6=substr($6, 0, 3); print $0;}'
>> a;2; 3;4;5 ;abc;7;8;9
>>
>> echo "a;2; 3;4;5 ;abcdefghijk;7;8;9" | awk -F';' '{OFS=";"}
>> {$6=substr($6, 0, 3); print $0}'
>> a;2; 3;4;5 ;abc;7;8;9
>
> The difference here is that in the first case, OFS is set exactly once
> at the beginning of the script. In the second, OFS is set for every
> line that is read from the file. Its a bit wasteful but not too bad.
Does that mean that with BEGIN it will run a little faster?
Did the semicolon at the end do anything? As in "print $0;}"
Thanks, Kathryn!
Mike