Note that each command is preceded by $
to distinguish it from output; do not type the $
.
We start with the data file.
$ cat data.txt
4|55504|214052
7|37107|214052
6|45206|214052
Let's extract the student id. When using a new command like cut
you might want to look up its wikipedia entry. You don't need to memorize these things, but it's better for your reasoning about the code to know each component's job.
$ cat data.txt | cut -d '|' -f 3
214052
214052
214052
Now make it unique:
$ cat data.txt | cut -d '|' -f 3 | uniq
214052
214063
214079
Now do something for each line:
$ cat data.txt | cut -d '|' -f 3 | uniq | while read student; do echo $student; done
At this point you probably want to move to a script file. Make it, make it executable, and open it in text edit.
$ touch schedules.sh
$ chmod +x schedules.sh
$ open -a TextEdit schedules.sh
Run the script as you work:
$ ./schedules.sh
Now write the command you've got as of now and try to do a grep
to find each student's courses, and then sort it by period with ... | sort -n
. Let me know if you need some help on this part.