AWK Question

Richard O'Keefe ok at cs.mu.oz.au
Thu Oct 5 20:28:52 AEST 1989


In article <281 at nisca.ircc.ohio-state.edu>, frank at hpuxa.ircc.ohio-state.edu (Frank G. Fiamingo) writes:
> 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.

New versions of awk may be different, but the 4.3BSD manual says
"The variable FS ... may be changed at any time to any single character."
By experiment, the awk that comes with SunOS 4.0 takes the first character
of FS as the only separator.

The following script does the trick:
BEGIN	{ n = 28 }
	{   if (substr($0, n, 1) == " ") {
		print substr($0, 1, n-1) "0" substr($0, n+1, length-n);
	    } else {
		print;
	    }
	}

Another approach would be to use sed.



More information about the Comp.unix.questions mailing list