Re: [PLUG] awk: is field blank?

2021-10-30 Thread Tomas Kuchta
Awk variable NF contains number of fieds. So: awk 'NF==8 { print }' Will print lines with 8 fields. Best, Tomas On Sat, Oct 30, 2021, 11:31 Rich Shepard wrote: > I've a 351K line file with 8 fields. About 50K of those lines has $8 blank. > I want awk to print only rows with values in all 8

Re: [PLUG] awk: is field blank?

2021-10-30 Thread Rich Shepard
On Sat, 30 Oct 2021, Robert Citek wrote: Simplified version of your script: BEGIN {FS="|"} $8 != " " Robert, Thanks for the insights. I've not been aware of some before. Regards, Rich

Re: [PLUG] awk: is field blank?

2021-10-30 Thread Robert Citek
A few pointers: - {print $0} and {print} are the same - {print} is the default action for any pattern match - since you are printing the entire line, the OFS isn't used and, therefore, doesn't need to be specified - you don't need to specify an "if" as that is part of the structure of an awk

Re: [PLUG] awk: is field blank?

2021-10-30 Thread Rich Shepard
On Sat, 30 Oct 2021, Robert Citek wrote: Here's a sample: $ echo -e "a\tb\tc\td\na\tb\t\td" | awk -F'\t' '{print}' a b c d a b d $ echo -e "a\tb\tc\td\na\tb\t\td" | awk -F'\t' '$3=="" {print}' a b d My script uses if and awk doesn't like how I've used it: BEGIN {FS="|";OFS="|"} if

Re: [PLUG] awk: is field blank?

2021-10-30 Thread Robert Citek
... and to negate the conditional use an exclamation point (!) : $ echo -e "a\tb\tc\td\na\tb\t\td" | awk -F'\t' '$3 != "" {print}' a b c d Regards, - Robert On Sat, Oct 30, 2021 at 9:46 AM Robert Citek wrote: > Sorry, this item didn't get pasted in my last post: > > $ echo -e

Re: [PLUG] awk: is field blank?

2021-10-30 Thread Robert Citek
Sorry, this item didn't get pasted in my last post: $ echo -e "a\tb\tc\td\na\tb\t\td" | awk '{print $1" = "$2" = "$3" = "$4}' a = b = c = d a = b = d = Notice that you have to specify the field separator with the -F option, otherwise awk compresses consecutive whitespace characters by default.

Re: [PLUG] awk: is field blank?

2021-10-30 Thread Robert Citek
Hello Rich, Here's a sample: $ echo -e "a\tb\tc\td\na\tb\t\td" | awk -F'\t' '{print}' a b c d a b d $ echo -e "a\tb\tc\td\na\tb\t\td" | awk -F'\t' '$3=="" {print}' a b d Good luck and let us know how it goes. Regards, - Robert On Sat, Oct 30, 2021 at 9:31 AM Rich Shepard wrote: > I've

[PLUG] awk: is field blank?

2021-10-30 Thread Rich Shepard
I've a 351K line file with 8 fields. About 50K of those lines has $8 blank. I want awk to print only rows with values in all 8 fields. I'm not finding how to tell awk to print $0 if $8 is not blank. My awk/sed book doesn't seem to have this information and my web searches aren't finding the