Skip to main content
spelling fix: "on" -> "own", plus obligatory additional 5+ characters of wordsmitthing
Source Link

Given such a requirement, I would use a GNU grep (for the -o option), then pass it through wc to count the total number of occurrences:

$ grep -o -i iphone Tweet_Data | wc -l 3 

Plain grep -c on the data will count the number of lines that match, not the total number of words that match. Using the -o option tells grep to output each match on its onown line, no matter how many times the match iswas found in the original line.

wc -l tells the wc utility to count the number of lines. After grep puts each match in its own line, this is the total number of occurrences of the word in the input.


If GNU grep is not available (or desired), you could transform the input with tr so that each word is on its own line, then use grep -c to count:

$ tr '[:space:]' '[\n*]' < Tweet_Data | grep -i -c iphone 3 

Given such a requirement, I would use a GNU grep (for the -o option), then pass it through wc to count the total number of occurrences:

$ grep -o -i iphone Tweet_Data | wc -l 3 

Plain grep -c on the data will count the number of lines that match, not the total number of words that match. Using the -o option tells grep to output each match on its on line, no matter how many times the match is in the line.

wc -l tells the wc utility to count the number of lines. After grep puts each match in its own line, this is the total number of occurrences of the word in the input.


If GNU grep is not available (or desired), you could transform the input with tr so that each word is on its own line, then use grep -c to count:

$ tr '[:space:]' '[\n*]' < Tweet_Data | grep -i -c iphone 3 

Given such a requirement, I would use a GNU grep (for the -o option), then pass it through wc to count the total number of occurrences:

$ grep -o -i iphone Tweet_Data | wc -l 3 

Plain grep -c on the data will count the number of lines that match, not the total number of words that match. Using the -o option tells grep to output each match on its own line, no matter how many times the match was found in the original line.

wc -l tells the wc utility to count the number of lines. After grep puts each match in its own line, this is the total number of occurrences of the word in the input.


If GNU grep is not available (or desired), you could transform the input with tr so that each word is on its own line, then use grep -c to count:

$ tr '[:space:]' '[\n*]' < Tweet_Data | grep -i -c iphone 3 
missed the input filename for tr
Source Link
Jeff Schaller
  • 68.8k
  • 35
  • 122
  • 266

Given such a requirement, I would use a GNU grep (for the -o option), then pass it through wc to count the total number of occurrences:

$ grep -o -i iphone Tweet_Data | wc -l 3 

Plain grep -c on the data will count the number of lines that match, not the total number of words that match. Using the -o option tells grep to output each match on its on line, no matter how many times the match is in the line.

wc -l tells the wc utility to count the number of lines. After grep puts each match in its own line, this is the total number of occurrences of the word in the input.


If GNU grep is not available (or desired), you could transform the input with tr so that each word is on its own line, then use grep -c to count:

$ tr '[:space:]' '[\n*]' < Tweet_Data | grep -i -c iphone 3 

Given such a requirement, I would use a GNU grep (for the -o option), then pass it through wc to count the total number of occurrences:

$ grep -o -i iphone Tweet_Data | wc -l 3 

Plain grep -c on the data will count the number of lines that match, not the total number of words that match. Using the -o option tells grep to output each match on its on line, no matter how many times the match is in the line.

wc -l tells the wc utility to count the number of lines. After grep puts each match in its own line, this is the total number of occurrences of the word in the input.


If GNU grep is not available (or desired), you could transform the input with tr so that each word is on its own line, then use grep -c to count:

$ tr '[:space:]' '[\n*]' | grep -i -c iphone 3 

Given such a requirement, I would use a GNU grep (for the -o option), then pass it through wc to count the total number of occurrences:

$ grep -o -i iphone Tweet_Data | wc -l 3 

Plain grep -c on the data will count the number of lines that match, not the total number of words that match. Using the -o option tells grep to output each match on its on line, no matter how many times the match is in the line.

wc -l tells the wc utility to count the number of lines. After grep puts each match in its own line, this is the total number of occurrences of the word in the input.


If GNU grep is not available (or desired), you could transform the input with tr so that each word is on its own line, then use grep -c to count:

$ tr '[:space:]' '[\n*]' < Tweet_Data | grep -i -c iphone 3 
added non-GNU / POSIX option
Source Link
Jeff Schaller
  • 68.8k
  • 35
  • 122
  • 266

Given such a requirement, I would use a GNU grep (for the -o option), then pass it through wc to count the total number of occurrences:

$ grep -o -i iphone Tweet_Data | wc -l 3 

Plain grep -c on the data will count the number of lines that match, not the total number of words that match. Using the -o option tells grep to output each match on its on line, no matter how many times the match is in the line.

wc -l tells the wc utility to count the number of lines. After grep puts each match in its own line, this is the total number of occurrences of the word in the input.


If GNU grep is not available (or desired), you could transform the input with tr so that each word is on its own line, then use grep -c to count:

$ tr '[:space:]' '[\n*]' | grep -i -c iphone 3 

Given such a requirement, I would use a GNU grep (for the -o option), then pass it through wc to count the total number of occurrences:

$ grep -o -i iphone Tweet_Data | wc -l 3 

Plain grep -c on the data will count the number of lines that match, not the total number of words that match. Using the -o option tells grep to output each match on its on line, no matter how many times the match is in the line.

wc -l tells the wc utility to count the number of lines. After grep puts each match in its own line, this is the total number of occurrences of the word in the input.

Given such a requirement, I would use a GNU grep (for the -o option), then pass it through wc to count the total number of occurrences:

$ grep -o -i iphone Tweet_Data | wc -l 3 

Plain grep -c on the data will count the number of lines that match, not the total number of words that match. Using the -o option tells grep to output each match on its on line, no matter how many times the match is in the line.

wc -l tells the wc utility to count the number of lines. After grep puts each match in its own line, this is the total number of occurrences of the word in the input.


If GNU grep is not available (or desired), you could transform the input with tr so that each word is on its own line, then use grep -c to count:

$ tr '[:space:]' '[\n*]' | grep -i -c iphone 3 
words
Source Link
Jeff Schaller
  • 68.8k
  • 35
  • 122
  • 266
Loading
Source Link
Jeff Schaller
  • 68.8k
  • 35
  • 122
  • 266
Loading