On Wed, Feb 14, 2024 at 10:47 AM Rich Shepard <[email protected]>
wrote:
> I've downloaded a data file where the permit type can be Active, Inactive,
> or Draft.
>
> Removing all Draft records was easy. Removing all Inactive records has so
> far escaped my gawk (and LO Calc) efforts because Inactive contains the
> substring 'active'.
>
> My script:
> BEGIN { FS = OFS = "," }
> NR ~ /1/ { print $0 }
> $4 == "Inactive" { next }
> $4 == "Active" { print $0 }
>
> I've also tried with matching:
> $4 ~ /Inactive/ { next }
> $4 ~ /Active/ { print $0 }
>
> And, of course, specifying only field 4 containing Active also fails.
>
> My AWK books and web searches haven't taught me how to write a pattern that
> matches only 'active' and not 'inactive.'
>
> Would the substr() function do the job? E.g,, substr(Active,1,6)
>
> Here are two sample records:
> 410 Auto Wrecking,410 Auto Wrecking,So3011780,Inactive,Industrial SW
> GP,27865 Sr 410 E,Buckley,Pierce,98321
> 410 Auto Wrecking,410 Auto Wrecking,WAR011780,Active,Industrial SW
> GP,27865 Sr 410 E,Buckley,Pierce,98321
>
>
you can exclude lines containing a given value with grep.
grep -v Inactive input.txt
this could cause problems if one of the other fields contained the word
Inactive but it's a start.
-wes