Filter lines based on values at specific positions

hi.

I have a Fixed Length text file as input where the character positions 4-5(two character positions starting from 4th position) indicates the LOB indicator. The file structure is something like below:

10126Apple DrinkOmaha      
10231Milkshake   New Jersey
103   Billabong    Illinois

The requirement is to capture all the record(here the first and second) that contains strings like "26", "31", "24" and "78" as LOB Indicators in the 4th and 5th position(there can be more valid LOB indicator values coming up in the near future) of each record.

I know the process of awk, but want to know if this could be done using grep/sed.

Regards,
Kumarjit.

Capture and do what with it?

sed -n 's/...\([0-9][0-9]\).*/\1/p' file

they will serve as input to another downstream process.

In your solution, you've just checked the value of two consecutive column positions starting from position 4 against any numeric values between 0 and 9, but the requirement is completely different, as the data in these two positions will have discrete values like "26", "31", "24" or "78".

How to achieve this without using AWK?

Regards.

Try:

grep -E '^...(26|31|24|78)' file

--
On Solaris use /usr/xpg4/bin/grep

cut -c 4,5 <your_file.txt

Thanks for all the feedback.

@Scrutinizer: What if the starting position of the LOB indicator field is 29th character position instead of 4th? Should I put 29 dots in my grep expression??

Warm Regards.
Kumarjit.

28 you mean? If it starts at the 29th position, you can try this:

grep -E '^.{28}(26|31|24|78)' file