With this input in the file /tmp/input2

This is the header line from the input file
410 Auto Wrecking,410 Auto Wrecking,So3011780,Inactive,Industrial SW
GP,27865 Sr 410 E,Buckley,Pierce,98321,ROW_1
410 Auto Wrecking,410 Auto Wrecking,WAR011780,Active,Industrial SW GP,27865
Sr 410 E,Buckley,Pierce,98321,ROW_2
410 Auto Wrecking,410 Auto Wrecking,So3011780,Inactive,Industrial SW
GP,27865 Sr 410 E,Buckley,Pierce,98321,ROW_3
410 Auto Wrecking,410 Auto Wrecking,WAR011780,Active,Industrial SW GP,27865
Sr 410 E,Buckley,Pierce,98321,ROW_4

Using this script in the file dogawk:

BEGIN { FS = OFS = "," }
NR ~ /1/ { print $0 }
$4 == "Inactive" { next }
$4 == "Active" { print $0 }

and with this command on bash:

gawk -f dogawk /tmp/input2

I get this output, with the header row and the Active rows, only:

This is the header line from the input file
410 Auto Wrecking,410 Auto Wrecking,WAR011780,Active,Industrial SW GP,27865
Sr 410 E,Buckley,Pierce,98321,ROW_2
410 Auto Wrecking,410 Auto Wrecking,WAR011780,Active,Industrial SW GP,27865
Sr 410 E,Buckley,Pierce,98321,ROW_4

For completeness, gawk --version outputs:

 GNU Awk 5.1.1, API: 3.1 (GNU MPFR 4.1.1-p1, GNU MP 6.2.1)
Copyright (C) 1989, 1991-2021 Free Software Foundation.

This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 3 of the License, or
(at your option) any later version.

This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
GNU General Public License for more details.

You should have received a copy of the GNU General Public License
along with this program. If not, see http://www.gnu.org/licenses/.
----gawk output ends----

If I instrument your script with printf's, like this:

BEGIN { FS = OFS = "," }
NR ~ /1/ { printf "I am executing the NR line "; print $0 }
$4 == "Inactive" { printf "I am executing the next branch\n"; next }
$4 == "Active" { printf "I think I am on an Active line "; print $0 }

and I run it again with the /tmp/input2 file, I get:

I am executing the NR line This is the header line from the input file
I am executing the next branch
I think I am on an Active line 410 Auto Wrecking,410 Auto
Wrecking,WAR011780,Active,Industrial SW GP,27865 Sr 410
E,Buckley,Pierce,98321,ROW_2
I am executing the next branch
I think I am on an Active line 410 Auto Wrecking,410 Auto
Wrecking,WAR011780,Active,Industrial SW GP,27865 Sr 410
E,Buckley,Pierce,98321,ROW_4

Suggestion: try inserting printf's to see what line of your script is
outputting what.

--Seth

Reply via email to