0

I have this code that counts the occurrences of different college majors within the file:

#!/bin/bash

file=$1
OUT=$( cat $file | cut -d',' -f3 | sort | uniq -c)
echo $OUT

That produces this output:

4 Computer Information Systems 2 Computer Science 2 History 1 Marketing 2 Social Studies

How do I get the output to look like this:

4 Computer Information Systems 
2 Computer Science
2 History
1 Marketing
2 Social Studies

With every major being on its own line?

This may seem like a silly question but I am very new to bash scripting. TIA for any help!

codeforester
  • 39,467
  • 16
  • 112
  • 140
  • `echo "$OUT"`. Quotes are important. – Charles Duffy Nov 14 '16 at 21:37
  • And don't use all-caps names for your own variables -- those names are used by variables with meaning to the shell or operating system, whereas names with at least one lower-case character are reserved for application use. – Charles Duffy Nov 14 '16 at 21:38
  • Consider making a habit of running your code through http://shellcheck.net/ before asking questions here. – Charles Duffy Nov 14 '16 at 21:41

1 Answers1

0

Don't assign the value to a variable, just this would do:

cut -d',' -f3 "$1" | sort | uniq -c
codeforester
  • 39,467
  • 16
  • 112
  • 140