This archive contains answers to questions sent to Unidata support through mid-2025. Note that the archive is no longer being updated. We provide the archive for reference; many of the answers presented here remain technically correct, even if somewhat outdated. For the most up-to-date information on the use of NSF Unidata software and data services, please consult the Software Documentation first.
>From: address@hidden >Organization: . >Keywords: 199907091514.JAA29497 >Steve, > >After I figured out that awk on Solaris is old "awk" and >won't accept -v, and used nawk instead..it works great. >I wonder if you could help with an awk question, that I >can't find the answer to in my awk book (a rather poor one). >Since the data is transmitted so many times, I get a lot of >repetitious data, is there a way to tell awk to only find >the requested pattern a set number of times?, say two or >three to allow for the "NIL" lines? > >Thanks >Robert > > Robert, You can put a counter in, and increment it after a non-NIL bulletin. Then test the counter on the original comparison line, eg: #!/bin/csh -f set ASTN=72403 set PART=PPDD set FILE=/shemp/data/ldm/upperair/199907091?_upa.wmo awk -v ASTN=${ASTN} -v PART=${PART} -v COUNT=0 \ 'index($0,ASTN) != 0 && index($0,PART) != 0 && COUNT == 0 { print \ while(index($0,"=") == 0) \ { getline; print $0 } \ if(index($0,"NIL") == 0) {COUNT = COUNT + 1} \ printf "\n" \ }' $FILE The above will still print out NIL lines and only increment COUNT when the "=" line doesn't have NIL in it. You can suppress the output of the NIL lines in the top pattern matching line by adding "&& index($0,"NIL") == 0". Steve Chiswell