Awk problem.

March 17, 2011 at 15:08:38
Specs: Windows 7
I'm really new with awk and I have a problem which I can't solve:

I have to display the maximum number of identical consecutive lines from each
input file given as argument and for each such line I have to display its
contents, number of the identicaly lines, and the name of the file
containing it.

See More: Awk problem.

Report •

March 17, 2011 at 16:24:30
This looks like homework so how about making an effort? I'll help to get you started. Consider this stub program:

awk ' {
   printf("NR: %s   FNR: %s %s\n", NR, FNR, FILENAME)
END { print NR }
' input1 input2

NR is the cumulative number of lines read
FNR is the number of lines read in the current file and resets to 1 each time a new file is processed.
FILENAME is an internal variable showing the current file being processed.

When the last file processes, I print out NR at the END.

I'll give you some further hints:

# print an entire line:
print $0

Basically, here is what you need to do: when NFR == 1 set a variable called previousline to $0 and continue. For each line read in the file, if the line equals previousline update your counter by 1.

Report •
Related Solutions

Ask Question