Path: utzoo!utgpu!jarvis.csri.toronto.edu!mailrus!tut.cis.ohio-state.edu!gem.mps.ohio-state.edu!ginosko!aplcen!haven!grebyn!macom1!larry From: larry@macom1.UUCP (Larry Taborek) Newsgroups: comp.unix.questions Subject: Re: AWK Question Message-ID: <4939@macom1.UUCP> Date: 9 Oct 89 11:47:47 GMT References: <281@nisca.ircc.ohio-state.edu> Organization: CENTEL Federal Systems, Reston, VA. 22091-1506 Lines: 42 From article <281@nisca.ircc.ohio-state.edu>, by frank@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@macom1.UUCP 11400 Commerce Park Drive Reston, VA 22091-1506 703-758-7000