I'll try to be specific and clear.
I have a file: log.txt it contains multiple strings that I search to print and count each of them.
This is my command, only print columns coincidences in the log.txt file:
sed -n '1p' log.txt | awk '{ s = ""; for(i = 25; i <= NF; i++) s = s $i "\n"; print s}'
Explanation
sed -n '1p' //prints the first line
awk '{ s = ""; for(i = 25; i <= NF; i++) s = s $i "\n"; print s}' //prints the next columns from the number 25 column
Input:
Column25 Column26 Column27 ColumnN <--#first filter:I need obtain specific headers. ColumnN
Column25 Column27 ColumnN
Column26 Column27 <--#Count how many times is repeat every string in whole file
Output:
Column25
Column26
Column27
Column28
Column29
ColumnN
I try to do:
From the previous output I want to count all the coincidences in the same file file.log but in the same command:
sed -n '1p' log.txt | awk '{ s = ""; for(i = 25; i <= NF; i++) s = s $i "\n"; print s}'
and send again to the output like:
Desired Output:
Column25 - n times
Column26 - n times
Column27 - n times
Column28 - n times
Column29 - n times
ColumnN - n times
PS. I've thinking in use the same variable "$s" in the for loop to start a search, but is not working.
i=25? From the examples, it just looks like you want to count how many times everything from Column 1 to Column N reappears in the file, and yet the way this reads is that you want to start counting only things that appear after Column 25