UNIX command -Filter rows in fixed width file based on column values

Hi All,

I am trying to select the rows in a fixed width file based on values in the columns.

I want to select only the rows if column position 3-4 has the value AB

I am using cut command to get the column values. Is it possible to check if cut -c3-4 = AB is true then select only that particular row.

cat file | cut -c3-4 > outputfile

File

123456789
23AB343Y6
46BB343N6
53AB343Y8
56BB343N6
56AB343N6
  1. I want the entire row if the value "AB" is present in column position 3-4.
  2. Select rows where column 3-4 =AB and Column 8 = Y

Any suggestions on filtering rows in fixed width file based on column values would be helpful.

Thanks
Ashok

Try:

grep '^..AB...Y' file
1 Like

Hi,

Thanks, It works fine with grep command.

Ashok