Skip to main content
edited tags; "I" is upper-case in English
Source Link
Jeff Schaller
  • 68.8k
  • 35
  • 122
  • 266

I have a text file containing tweets and I'm required to count the number of times a word is mentioned in the tweet. For example, the file contains:

Apple iPhone X is going to worth a fortune The iPhone X is Apple's latest flagship iPhone. How will it pit against it's competitors? 

And let's say iI want to count how many times the word iPhone is mentioned in the file. So here's what I've tried.

cut -f 1 Tweet_Data | grep -i "iPhone" | wc -l 

it certainly works but I'm confused about the 'wc' command in unix. What is the difference if iI try something like:

cut -f 1 Tweet_Data | grep -c "iPhone" 

where -c is used instead? Both of these yield different results in a large file full of tweets and I'm confused on how it works. Which method is the correct way of counting the occurrence?

I have a text file containing tweets and I'm required to count the number of times a word is mentioned in the tweet. For example, the file contains:

Apple iPhone X is going to worth a fortune The iPhone X is Apple's latest flagship iPhone. How will it pit against it's competitors? 

And let's say i want to count how many times the word iPhone is mentioned in the file. So here's what I've tried.

cut -f 1 Tweet_Data | grep -i "iPhone" | wc -l 

it certainly works but I'm confused about the 'wc' command in unix. What is the difference if i try something like:

cut -f 1 Tweet_Data | grep -c "iPhone" 

where -c is used instead? Both of these yield different results in a large file full of tweets and I'm confused on how it works. Which method is the correct way of counting the occurrence?

I have a text file containing tweets and I'm required to count the number of times a word is mentioned in the tweet. For example, the file contains:

Apple iPhone X is going to worth a fortune The iPhone X is Apple's latest flagship iPhone. How will it pit against it's competitors? 

And let's say I want to count how many times the word iPhone is mentioned in the file. So here's what I've tried.

cut -f 1 Tweet_Data | grep -i "iPhone" | wc -l 

it certainly works but I'm confused about the 'wc' command in unix. What is the difference if I try something like:

cut -f 1 Tweet_Data | grep -c "iPhone" 

where -c is used instead? Both of these yield different results in a large file full of tweets and I'm confused on how it works. Which method is the correct way of counting the occurrence?

Source Link
Maxxx
  • 881
  • 1
  • 8
  • 8

Counting occurrences of word in text file

I have a text file containing tweets and I'm required to count the number of times a word is mentioned in the tweet. For example, the file contains:

Apple iPhone X is going to worth a fortune The iPhone X is Apple's latest flagship iPhone. How will it pit against it's competitors? 

And let's say i want to count how many times the word iPhone is mentioned in the file. So here's what I've tried.

cut -f 1 Tweet_Data | grep -i "iPhone" | wc -l 

it certainly works but I'm confused about the 'wc' command in unix. What is the difference if i try something like:

cut -f 1 Tweet_Data | grep -c "iPhone" 

where -c is used instead? Both of these yield different results in a large file full of tweets and I'm confused on how it works. Which method is the correct way of counting the occurrence?