Hello forum,
I need to append the total line count to the end of each line in a file.
The file where this line count needs to be appended is generated by this script:
The script does a word frequency count by the first column of a file.
if I add wc -l at the end then the line count appears only in the last line. But I want the line count to appear at the end of each line.
Thanks!
Hi
Provide a sample input file and an expected output file.
Guru.
Sample input:
aaa bbb ccc
aaa bbb ccc
ddd eee fff
ddd eee fff
The output from my script will be:
2 aaa
2 ddd
I want the sum of occurrence of aaa and bbb =2+2 i.e. the line count to show up at the end of each line
i.e. output will be:
2 aaa 4
2 ddd 4
Hi
awk '{a[$1]++; j++}END{ for (i in a) print a,i,j;}' infile
Guru.
1 Like
Thanks that works fine except that the sorting by the number of occurrences of the words is not there. I appreciate your help.
---------- Post updated at 12:43 AM ---------- Previous update was at 12:25 AM ----------
ok..i got it now...thanks