How can I make a where clause in a Linux shell?

I have a CSV file and I would like to filter out all rows in which the 19th column has two or more characters. I know the individual parts, but I cannot figure out how to glue them together. First I have to stitch the file. The following prints the 19th column

awk -F "," '{print $19}' file.txt 

awk also has length and ifs

And I know that all this needs to be glued together using pipes. I am simply obsessed with the exact syntax since I haven’t done bash programming before.

+4
source share
2 answers

AWK is a series of pairs of template actions written as:

 condition { action } 

The condition part is your filter.

For example, to get all the rows (the 19th column has at least 2 characters):

 $ awk -F, 'length($19)>1' file.txt 

When the {action} missing, the default action is to print the entry.

+8
source

This should work:

 awk -F ',' '{if (length($19) < 2) { print $0 }}' file.txt 

It prints the entire line if the length of the 19th field is less than 2.

+1
source

Source: https://habr.com/ru/post/1403205/


All Articles