Skip to content

Instantly share code, notes, and snippets.

@naezith
Created January 4, 2016 12:30
Show Gist options
  • Save naezith/397e0bde868a9000dff8 to your computer and use it in GitHub Desktop.
Save naezith/397e0bde868a9000dff8 to your computer and use it in GitHub Desktop.
Filter a list of data
inf="input_list.txt" # this file has lines like [201504695,ASLI,ASLAN,[email protected],CS101,89,2]
outf="list.txt"
sep=',' #define seperator
#filter the list
list=$(cat $inf `
`| egrep "2015.*(CS101|CS102),([6-9][0-9]|100).*" ` # filter with CS101 OR CS102, 2015 and 60 <= mark
`| sed 's/-//1' ` # remove - from the number
`| awk -F $sep 'int($7)==2' ` # second time they take the lesson
`| awk -F $sep 'int($6)<90' ` # mark < 90
`| sort -t $sep -k6,6nr -k2,2) # sort by score high to low, name low to high
#remove the output file if it exists
rm $outf
#save whole list into output file
for line in $list
do
echo "[$line]" >> $outf
done
#line count
echo "Line count: \c"; echo "$list" | wc -l
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment