Since you don't know AWK too well, may I suggest to skip it altogether and switch to PERL?
But first things first. What problem are you really trying to solve?
Seems to me you obtained a list of file names (DIR/COL=2/OUT=x.x)
You want to use that list to generate a rename where the file with the highest version number becomes number 1, the next down 2 and so on.
Is that correct?
I hope there no need to worry about overlap perhaps thanks to a version limit in place.
DCL defaults can do that just fine.
- Using PERL here just as a handy way to create a bunch of files
- Using FILE_ID to show which file is which
Here it goes.
$perl -e "open X,qq(>file.log;$_) for 1997..2000"
$dir/file
FILE.LOG;2000 (59705,105,0)
FILE.LOG;1999 (46771,399,0)
FILE.LOG;1998 (42897,980,0)
FILE.LOG;1997 (24538,519,0)
$rena/log file.log.* tmp.log;
%RENAME-I-RENAMED, FILE.LOG;2000 renamed to TMP.LOG;1
%RENAME-I-RENAMED, FILE.LOG;1999 renamed to TMP.LOG;2
%RENAME-I-RENAMED, FILE.LOG;1998 renamed to TMP.LOG;3
%RENAME-I-RENAMED, FILE.LOG;1997 renamed to TMP.LOG;4
$rena tmp.log;* file.log/log
%RENAME-I-RENAMED, TMP.LOG;4 renamed to FILE.LOG;4
%RENAME-I-RENAMED, TMP.LOG;3 renamed to FILE.LOG;3
%RENAME-I-RENAMED, TMP.LOG;2 renamed to FILE.LOG;2
%RENAME-I-RENAMED, TMP.LOG;1 renamed to FILE.LOG;1
$dir/file file.log;*
FILE.LOG;4 (24538,519,0)
FILE.LOG;3 (42897,980,0)
FILE.LOG;2 (46771,399,0)
FILE.LOG;1 (59705,105,0)
ok? No helpers needed. Just two commands relying on the ";" magic to stop inheritance.
Now let's see how to do this in Perl directly.
$ dir/file
FILE.LOG;2000 (59705,105,0)
FILE.LOG;1999 (46771,399,0)
FILE.LOG;1998 (42897,980,0)
FILE.LOG;1997 (24538,519,0)
$ perl -e "for (<file.log;*>) {$i++; $old = $_; s/;\d+/;$i/; rename $old, $_}"
$ dir/file
FILE.LOG;4 (24538,522,0)
FILE.LOG;3 (42897,983,0)
FILE.LOG;2 (46771,402,0)
FILE.LOG;1 (59705,108,0)
Broken down in steps:
<xxx> = glob("xxx") = glob(qq(xxx) = wildcard lookup with interpolated string.
for (<file.log;*>) # Loop over all files matching pattern, output into $_
{ # code block
$i++; # increment for each iteration. start at 1
$old = $_; # save the fetched file name
s/;\d+/;$i/; # substitute a semicolon followed by numbers
rename $old, $_ # Actual rename. Try with PRINT first.
} # end of code block
ok?