I have two  files one with 17k lines and another one with 4k lines. I wanted to compare position 115 to position 125 with each line in the second file and if there is a match, write the entire line from the first file into a new file. I had come up with a solution where i read the file using 'cat $filename | while read LINE'. but it's taking around 8 mins to complete. is there any other way like using 'awk' to reduce this process time.my codecat $filename | while read LINEdo  #read 115 to 125 and then remove trailing spaces and leading zeroes  vid=`echo $LINE | cut -c 115-125 | sed 's,^ *,,; s, *$,,' | sed 's/^[0]*//'`  exist=0  #match vid with entire line in id.txt  exist=`grep -x $vid $file_dir/id.txt | wc -l`  if [[ $exist -gt 0 ]]; then    echo $LINE >> $dest_dir/id.txt  fidone
comparing lines with awk vs while read line
text processing;sed;awk;search
The following should work, updated to strip white space:#!/usr/bin/awk -f# NR is the current line number (doesn't reset between files)# FNR is the line number within the current file# So NR == FNR  takes only the first fileNR == FNR {    # Mark the current line as existing, via an associative array.    found[$0]=1    # Skip to the next line, so we don't go through the next block    next}{    # Take the columns we're looking for    cols = substr($0,115,11)    # Strip whitespace (space and tab) from the beginning (^) and end ($)     gsub(/^[ \t]+/,, cols)    gsub(/[ \t]+$/,, cols)    # Check the associative array to see if this was in the first file    # If so, print the full line    if(found[cols]) print;}       Put it in a file and call with one of the followingawk -f script.awk patterns.txt full.txt./script.awk patterns.txt full.txt