bash how to remove rows if specific field is blank 1

bash how to remove rows if specific field is blank

# Basic syntax:
awk -F'delimiter' '$column# != ""' input_file

# Example usage:
awk -F'\t' '$3 != ""' input_file
# This prints every line in which the 3rd tab-delimited column is 
# not blank. Change the 3 to any column and/or add other conditions 
# for your application

Here is what the above code is Doing:
1. The -F’\t’ tells awk to use the tab character as the field separator.
2. The ‘$3 != “”‘ tells awk to print every line in which the 3rd column is not blank.
3. The input_file is the file you want to filter.

You can also use awk to filter based on multiple conditions. For example, if you want to filter based on the 3rd column being not blank and the 4th column being equal to “A”, you would use:

awk -F’\t’ ‘$3 != “” && $4 == “A”‘ input_file

Similar Posts