#!/usr/bin/gawk -f BEGIN { check=1; things=0; while(getline x < F) { if(check==1){ split(x,words,","); for(i in words){ things++; } check=0; } if((x !~ /Terminated/)&&(x !~ /cost/)) { split(x, lines,","); print lines[things-1]","lines[things]; } } close(F); }