Comparing Counts Within Separate Files

Hey all,

So I have this challenge where I am attempting to compare record counts from within several different log files. I want input and output counts for each file, and I want to compare that with the result of the input/output comparison from a separate--but related file.

Example:

File 1A has input and output rec count of 4, I need to then check
File 1B to ensure that it, too, has an input/output rec count of 4.

Then I move on to files 2A and 2B, 3A and 3B, etc.

Here is what I have set up so far:

I have each file set to its own variable, so file1A=/dir/dir/.../file1A.out, etc.
Then, I have a variable which contains all the file variables, so FILELIST="$file1A $file1B...", etc.
Next, I have a for loop--for i in $FILELIST; do...
Inside that for loop, I am making my file i/o comparisons.

My question is this, is there a way to increment that variable (pointer?) to the related second file for each, so that I can compare the i/o record counts between them? In other words, outside of the looping construct, which increments the counter, how do I make the variable go ahead and increment before it reaches the top of the for loop again. And also, can I--after comparing a set of related files--move to the THIRD file in the list, skipping over both the files I just compared.

I hope I have explained my situation clearly enough. If I am going completely down the wrong path with my logic constructs, please tell me that, too. I am using ksh.

Thank you

file1A="./file1A.out"
file1B="./file1B.out"
FILELIST="$file1A $file1B"
for fname in `eval echo $FILELIST`
do
cnt=`wc -l $fname|cut -d' ' -f1`
echo $cnt
done

I guess the crux of what I'm asking is, is there a way to specify which in a list of files your "pointer" points to?

So, when you have a variable that looks like FILELIST="$file1A $file1B...", how can you pull, say, the third variable from that list, without stating the name of the variable explicitly. I'm assuming the shell somehow stores a "bookmark", so to speak, of where it currently is in that list, or else the for loop wouldn't work. How can I find and use that bookmark to compare these files, if there is a way.

I don't really understand the eval statement, but through doing some testing, it doesn't seem to behave much differently than just the for statement itself (for fname in $files).

Please excuse my ignorance. I know just enough ksh scripting to be dangerous! :slight_smile: