-1

I have a big text file, it has 46 columns in total:

INPUT

Column1 Column2 ... Column46

I need to enumerate and count how many times repeat in themselves from column 17 until the 46. For example:

My file is like:

Column17 Column18 Column19 Column20 Column21 Column22 Column23 ... Column46

Column17 Column18 Column19 Column20 Column21 Column22 Column23 ... Column46
Column17 Column18          Column20          Column22
         Column18          Column20
                           Column20

Desired Output:

1 Column17 - 2 times
2 Column18 - 3 times
3 Column19 - 1 time
4 Column20 - 4 times
5 Column21 - 0 times
6 Column22 - 2 times
7 Column23 - 1 time
    " "    - N times
29 Column46 - 1 times

My awk Command:

awk '{n=1;if(NR==1)n=25;for(i=n;i<=NF;i++) a[$i]++} END{for(val in a) print val,a[val]}' filelog.txt

Actual Output:

Column1 ... Column46
bla 1 blaN...3 bla 3 
bla 3 blaN...2 bla 5
bla 7 blaN...4 bla 7

Takes all and every string of the whole file and count how many times repeat themselves. For example:

Column1 //There are 54 lines, takes all words/strings of that column
bla 3 //The 3 and 4, is the number of repetitions.
bla 4

But my command counts all the columns (from the 1, until 46) and every phrase in themselves, and the thing I want is count from the 17 until the 46 like the Desired Output Is there any way to make with my same command? or is necessarily to make it by other one?

  • 2
    Show your actual output. – Dip Aug 10 '18 at 5:45
  • @Dip I've added more information about the Output, if you have more doubts, please ask me more about it. Thank you! – Mareyes Aug 10 '18 at 5:55
  • 1
    On what basis you say Column21 count is 0 and Column19 count is 1 ? – Rakesh Sharma Aug 11 '18 at 3:19
  • How are the columns separated? – Rakesh Sharma Aug 11 '18 at 3:21
  • All the columns are separated one by each other. – Mareyes Aug 12 '18 at 3:24
0

Use cat command with -n option for enumeration.

And specify n=17 as you wants to start from there.

Use following command:

cat -n <(awk '{n=17;if(NR==1)n=25;for(i=n;i<=NF;i++) a[$i]++} END{for(val in a) print val,a[val]}' filelog.txt)
0

If I understand your requirements correctly, then this is the problem:

{n=1;if(NR==1)n=25;for(i=n;i<=NF;i++) ...

For every record except the first, you set n=1. Then you process all columns starting from n. But you actually want to set n=17.

  • It does again the same thing... start the count from the column one. – Mareyes Aug 12 '18 at 3:25
  • I'm sorry, I don't understand your comment. – Michael Vehrs Aug 13 '18 at 8:39
  • With your command starts to count from the first line to the last one. But you've helping to me, Thanks a lot! – Mareyes Aug 14 '18 at 2:48
  • That's not my command, that's yours. I said you need to set n=17. – Michael Vehrs Aug 14 '18 at 9:58

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.