Can grep a specific column?

Hello All

I have an input file with data below. I would like to grep and display the data where 3rd column contains string or at least one character. Kindly please help me with this!

Input:

tjfa3|zznpou|224fdd.34.ff3.35                  |Tiv|Otj|1
fgduul7|zznikj|                                          |Hff|Pvb|5
tjfa3|zzntre|gfhk-fdg.dff.45.fg-5               |LPO|Kio|8
ergiy4|zznytr|                                            |Nzm|Opi|2
hjauuyy2|zznuyt|23.54.gd.gdg.677           |Iud|Hui|1
fgduul7|zznioi|gfdgd-ff564fdv.dsg-gd.dg |Opg|Opi|

Needed Output:

tjfa3|zznpou|224fdd.34.ff3.35                  |Tiv|Otj|1
tjfa3|zzntre|gfhk-fdg.dff.45.fg-5               |LPO|Kio|8
hjauuyy2|zznuyt|23.54.gd.gdg.677           |Iud|Hui|1
fgduul7|zznioi|gfdgd-ff564fdv.dsg-gd.dg |Opg|Opi|

Thank you in advance for your help.

DoveLu

Please use code tags as required by forum rules!

You mean "third column in a pipe delimited file not empty"?

What have you tried so far?

Have a look at awk .
Hth

Note that <space>s and <tab>s are characters. So, according to your requirements, the output should be an exact copy of your input.

Assuming that you are looking for a 3rd field that contains at least one character that is not a whitespace character, this could be done with grep or sed , could be done a little bit easier with grep -E , and could be done still easier with awk .

Please clarify your requirements (and, as requested by Franklin52) show us what you have tried and tell us where it is falling short of your goal (using CODE tags to display your code and the output you're getting from it).

And, please explain whether "grep" in "I would like to grep" is an explicit requirement to use the grep utility or a verb indicating that you want to perform a generic global regular expression search and print matching lines.

Hello All,

I would like to filter all lines, which contains at least one visible character in the third column. Hopefully, it is clear now. I would appreciate for any solution with grep or awk.

Thank you in advance.

awk -F"|" '$3 ~ /[^\r\n\t ]/' inputfile > outputfile

We repeat: Please show us what you have tried to solve this problem!

1 Like