I want to compare the number of lines of each file and choose the one that contains the maximum number of lines for example
JavaScript
x
filename_V1 |wc -l =100
filename_V2 |wc -l =19
filename_V3 |wc -l =10
myFile_V1 |wc -l =1
myFile_V2 |wc -l =10
myFile_V3 |wc -l =15
I will get as result
JavaScript
filename_V1
myFile_V3
Advertisement
Answer
Alternative with lot’s of piping
JavaScript
wc -l *_V* | # generate the list
sed 's/_V/ _V/;$d' | # separate baseline from versions, delete total
sort -k 2,2 -k 1,1nr | # sort by names and size (reverse)
sort -k 2,2 -u | # get the first by name (max by design)
sed 's/ _V/_V/' | # reverse baseline name back to original
awk '{print $2}' # extract the filename
this script assumes the file names are under your control and space or _V won’t appear in the base names. Otherwise check out @Qualia’s version.