2

I have a text field that has lines with the following format:

game,match_num,list_of_players,game_date

Eg:

Football,1,james,john,jack,09-10-2018

I need to compare lines in the file based on the game and count only the unique lines i,e., count if the game name is not equal. How can I do this using sed or awk?

Something like this:

wc -l filename | awk -F, '$1 != $1'

I did not get any output for this command but I want to get the number of lines. So how should I change this command to get the desired output?

Lax_Sam
  • 225
  • Using an answer from the duplicated question: awk -F, '!seen[$1]++' filename | wc -l – Kusalananda Apr 01 '19 at 11:35
  • Ok. I tried the solution in the link you mentioned but I had given wc -l in the beginning instead of at the end. I should still read more about how to use pipes in linux. Your solution is what I was looking for. – Lax_Sam Apr 01 '19 at 11:39
  • The main thing to remember about pipes in the shell is that the result of a command on the left is piped into the input of the command on the right. Here, you want to count the unique lines. The command on the left produces the unique lines, and the command on the right counts them. – Kusalananda Apr 01 '19 at 11:41

0 Answers0