Grep matched records from huge file

111111111100000000001111111111
123232323200000010001114545454
232435424200000000001232131212
342354234301000000002323423443
232435424200000000001232131212
2390898994200000000001238908092
This is the record format.
From 11th position to 20th position in a record there are 0's occuring,and in some records there are value in between 11th to 20th positoin.

Now i want to grep only 4 nd 6 reocrd from a dat file,and if those records having numeric in between 11th to 20th position ie 0000100000,(only 1 will occur at any place from 11th to 20th).

Please help me out.

---------- Post updated at 02:02 PM ---------- Previous update was at 01:42 PM ----------

need only 4th and 6th records with 000000000 's from 11 to 20th position and 1 anyware in between.0's

Record Format

111111111100000000001111111111
123232323200000010001114545454
232435424200000000001232131212
342354234301000000002323423443
232435424200000000001232131212
2390898994200000000001238908092

Try this:

awk '(NR==4 || NR==6) && int(substr($0,11,10))' file

Hi Frank,

Can u please extend this query for any no of records in the .dat file which is having 0's from 11th to 20th position in a record(lenght unkown)and having 1 in between.

Hi, For the 6th record, I don't see 1 inbetween 11th & 20th position. Only for the 2nd & 4th records i can see your condition matching. Please could you explain why 6th record has to be present in the output.

HI latha,

That is example record set which i have pasted there.

there are millions of records in the file.

The command in the 2nd post selects records from line 4 or 6 with a number > 0 between position 11 and 20.

To select every record with a 1 between position 11 and 20:

awk 'int(substr($0,11,10))==1' file
while read record
do
a=`echo $record | cut -c11-20`
echo $a | grep 1 1>/dev/null
if [ $? -eq 0 ]
then
echo $record >>output
fi
done<input

---------- Post updated at 05:35 AM ---------- Previous update was at 05:30 AM ----------

Or

 
 awk '{ if( substr($0, 11, 10) ~ /1/ ) { print } }' inputfile