I have used the below code to print the previous line where the file contains a single token #! /bin/kshfile=input.txtwhile read linedoawk 'NF == 1 { print LAST } { LAST=$0 }'done < $fileNow I need to traverse through the result and need to check 9th position, 11th, 13th, etc. till the end of the line with the consecutive odd positions and if those positions are not matching with any of the mentioned numerics:201 230 197 193 229 200 215 226 001 198 It should print the error as CORRUPTED, if not AVAILABLE should be printed. Here is the example of my file :59 6 18 2014 169 7 14 2 7671912 7849744 201 460 6 19 2014 170 5 49 2 7671912 7849744 201 561 6 20 2014 171 6 8 2 7671912 7849744 201 662 6 23 2014 174 5 3 2 7671912 7849744 201 763 6 23 2014 174 7 17 2 7671912 7849744 201 864 6 24 2014 175 16 13 2 7671912 7849744 201 965 6 25 2014 176 8 20 2 7671912 7849744 201 10101 1 49 6 16 2014 7 39 201 1 0 1043 <au_launchpad_back.gif> 201 gif <SIZE> 8711 2 49 6 17 2014 13 15 201 1 0 1043 <au_launchpad_back.gif> 201 gif <SIZE> 8711 3 49 6 18 2014 1 38 201 1 0 1043 <au_launchpad_back.gif> 201 gif <SIZE> 8711 4 49 6 18 2014 7 14 201 1 0 1043 <au_launchpad_back.gif> 201 gif <SIZE> 8711 5 49 6 19 2014 5 49 201 1 0 1043 <au_launchpad_back.gif> 201 gif <SIZE> 871If we consider this as example 9th position is 7671912NOTE : The code should be feasible at any other file as well.
After printing the previous line where the file contains a single token now need to traverse through the result to meet the requirement
linux;shell script
Try this:$ echo 65 6 25 2014 176 8 20 2 7671912 7849744 201 10 |awk 'FNR == NR { a[$1]; next }     {         for (i = 9; i <= NF; i += 2) {             if (!($i in a)) {                 flag = 1;             }          }          if (flag) {              print CORRUPTED;                            } else {              print AVAILABLE;                            }     }' file -CORRUPTEDfile contains all your numerics to compare. You must replace echo 65 6 25 2014 176 8 20 2 7671912 7849744 201 10 from this test by script which print previous line where the file contains a single token.ExplanationFNR == NR { a[$1]; next }: while processing file, we save each number in file to an array a.After reading file, we loop through all odd fields, starting at field 9th, if field value not in array a, we set flag = 1.Finally, if flag is set to 1, meaning we have at least one field that its value not in file, so we print CORRUPTED, otherwise print AVAiLABLE.