2

I have a file like below.

Name1 IM123
Name2 IM145
Name1 IM901

I want to count the number of occurrences of the name.

0

2 Answers 2

2

$ grep "Name" test.txt | wc -l

As @kojiro nicely pointed out wc is not needed.

$ grep --count "Name" test.txt 

See man wc and man grep.

Sign up to request clarification or add additional context in comments.

Comments

0

You could try the following:

For specifically Name1:

$ awk '$1 ~ /Name1/ {++c} END {print c}' FS=" " file_name.txt

For all names:

$ awk '{count[$1]++}END{for(j in count) print j,"("count[j]" times)"}' FS=" " file_name.txt

Hope that helps!

1 Comment

I'm glad I could help. =) Make sure to accept any correct answer in order to close down questions for other users.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.