2

I created a .csv file (separated by ; instead of ,) that includes movie titles, movie rankings, movie years, and imdb rating from http://www.imdb.com/chart/top. Now I am trying to figure out how many movies were released before a given year. The year will be determined by the first shell input argument. Here is what I have so far:

awk -F "\"*;\"*" '$4 < 1950 {print ;}' result.csv | more | wc -l

Instead of "1950", I need it to be the first shell argument ($1). Using $1 instead of 1950 is telling the machine to compare the 4th column to the 1st column. I need to compare the 4th column with the 1st argument.

I need to run the file with the 1st argument being 1950:

./filename.sh 1950 

2 Answers2

1
awk -F '"*;"*' -v d="$1" '$4 < d' result.csv
Ed Morton
  • 188,023
  • 17
  • 78
  • 185
0

you can do counting in awk as well

awk -F'"*;"*' -v year=$1 '$4<year{count++} END{print count}' file
karakfa
  • 66,216
  • 7
  • 41
  • 56