'How to extract lines containing blank in a specific column with Linux command

Example:

aa\tab\tac\tad\tae
ba\tbb\tbc
ca\tcb\tcc
da\tdb\tdc\tdd

Expected output:

ba\tbb\tbc
ca\tcb\tcc

I want to extract lines containing blank in a 4th column with linux command. If you know the command, could you let me know it?



Solution 1:[1]

Using awk

$ awk -F"\\" '{if($4=="") print}' input_file
ba\tbb\tbc
ca\tcb\tcc

Solution 2:[2]

You can use cut and use "" as delimiter and check the field 4 if it is not empty. Then use the grep -v to check if a trailing "" exists or not. in an If statement you can get the result.

text='aa\tab\tac\'    

if [[ -z $(echo $text | cut -d \\ -f 4 | grep -v \\\\\$) ]]; then
    if[[ -z $(echo $text | grep -v \\\\\$) ]]; then
        echo $text
    else
        echo 'Text has a slash at the end'
    fi
else 
    echo 'Not valid input'
fi

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 HatLess
Solution 2 Mehrwarz