awk to select rows based on condition on column

I have got a file like this
003ABC00281020091005000100042.810001
003ABC01281020091005000100042.810001
003DEF00281020091005000100044.180001
003DEF01281020091005000100044.180001
003GHI00281020091005000100046.130001
003GHI01281020091005000100046.130001
003DKK00281020091005000100009.370001

i want output like this

003ABC00281020091005000100042.810001

003DEF00281020091005000100044.180001

003GHI00281020091005000100046.130001
003DKK00281020091005000100009.370001
i mean i want to select rows only when 8th character of the line is 0... Is it possible to do it using awk...pls help...
(pls ignore the space between lines :slight_smile:

1 Like

try this ...

awk '{chaine=substr($0,8,1);if (chaine==0) print $0}' file
1 Like

If you need keep the line position:

$ awk '{if (substr($0,8,1)==0) {print $0} else {print ""} }' urfile
003ABC00281020091005000100042.810001

003DEF00281020091005000100044.180001

003GHI00281020091005000100046.130001

003DKK00281020091005000100009.370001
nawk ' (substr($0,8,1) == "0"){printf("%s\n\n", $0)} ' file

Try to grep

grep -E "^.{7}0" inFile

Try this one to


cat yourfile | awk -F "" '{ if ($8==0)  print $0 }'

Where yourfile is the input file

Avoid the usage of "cat" here.

awk -F "" '{ if ($8==0)  print $0 }' yourfile
awk '$8==0' FS= infile

Not all awk versions support empty FS :cool:

thnx all for your quick response.. its working now