AWK Question
Larry Taborek
larry at macom1.UUCP
Mon Oct 9 21:47:47 AEST 1989
>From article <281 at nisca.ircc.ohio-state.edu>, by frank at hpuxa.ircc.ohio-state.edu (Frank G. Fiamingo):
> My problem is that I want to check a particular character
> position in a record to see whether or not it is a blank.
> If so, I want to change it to a zero. I thought I could
> do this with an awk script similar to the one below, but have
> had no success.
>
> BEGIN {FS=""}
> {split($0,array);
> if (array[28] == " ") {array[28] = 0};
> for(i in array) print array[$1]}
>
> However, it appears that split is only recognizing 2 fields
> in the record, rather than the 35 characters that it contains.
> Can anyone tell me where I've gone wrong, or a better way
> to do this?
Frank,
Why use split at all? If $0 contains the entire record, and if
you have fixed position data (as array[28] suggests) then why not
just check $0[28]?
{
FS=""
array=$0
if (array[28] == " ") array[28] ="0"
print array
}
I had to assign $0 to some variable as I wanted to change it.
Awk complains if you try to change $fields directly. You can
also remove the FS="" statement, as we are working off $0 then
any fields that awk derives are of no consequence to this code.
Hope this helps...
--
Larry Taborek ..!uunet!grebyn!macom1!larry Centel Federal Systems
larry at macom1.UUCP 11400 Commerce Park Drive
Reston, VA 22091-1506
703-758-7000
More information about the Comp.unix.questions
mailing list