Skip to content

Instantly share code, notes, and snippets.

@mattneary
Last active August 29, 2015 14:05
Show Gist options
  • Save mattneary/b09bb9a1a04a2493ed5b to your computer and use it in GitHub Desktop.
Save mattneary/b09bb9a1a04a2493ed5b to your computer and use it in GitHub Desktop.
A programming exercise.
4|55504|214052
7|37107|214052
6|45206|214052
1|15901|214052
8|10208|214052
3|35803|214052
2|30002|214052
5|50205|214052
6|51506|214063
4|55504|214063
1|45201|214063
3|50803|214063
2|35702|214063
7|10207|214063
5|16005|214063
7|10507|214079
4|16204|214079
3|45203|214079
1|50201|214079
8|35808|214079
2|10202|214079
5|55305|214079
7|37107|214097
4|16204|214097
3|45203|214097
8|50208|214097
2|35802|214097
5|12305|214097
1|56501|214097
3|45403|214058
1|15901|214058
4|45204|214058
6|50306|214058
5|35805|214058
8|10208|214058
7|56507|214058
3|36903|214090
5|16205|214090
1|45201|214090
2|40102|214090
8|35808|214090
6|10206|214090
7|50207|214090
1|50201|214091
4|16204|214091
5|45205|214091
8|30408|214091
3|35703|214091
7|10207|214091
6|55106|214091
3|50303|214093
5|15905|214093
8|45208|214093
6|36806|214093
7|12307|214093
2|06802|214093
1|03001|214093
1|08001|214081
4|51204|214081
5|45205|214081
2|30002|214081
3|35703|214081
6|06506|214081
7|16007|214081
8|10208|214081
5|37105|214098
7|15907|214098
3|45203|214098
1|50201|214098
2|35802|214098
4|10204|214098
6|30406|214098
1|51201|214095
5|45205|214095
4|06004|214095
3|15703|214095
2|35702|214095
7|10207|214095
6|55106|214095
3|15403|214083
7|51507|214083
5|45205|214083
4|50304|214083
8|10208|214083
6|55106|214083
2|36402|214083
3|36903|214075
5|45205|214075
7|11007|214075
2|50202|214075
8|35808|214075
1|10201|214075
6|30406|214075
8|50208|214077
7|15907|214077
1|45201|214077
5|30405|214077
6|06506|214077
2|35802|214077
3|10203|214077
3|50803|214053
6|45206|214053
8|08408|214053
2|40102|214053
1|35801|214053
4|10204|214053
7|50207|214053
3|10903|214070
8|15308|214070
4|41204|214070
5|45205|214070
1|56501|214070
7|12307|214070
6|50306|214070
2|36402|214070
4|50804|214082
1|36901|214082
8|45208|214082
5|30405|214082
6|35706|214082
3|10203|214082
2|15702|214082
1|36901|214051
5|15905|214051
6|45206|214051
8|50208|214051
3|35803|214051
2|10202|214051
7|06607|214051
3|36903|214087
1|15901|214087
5|45205|214087
6|50306|214087
2|10202|214087
7|30407|214087
8|36808|214087
7|50207|214054
4|16704|214054
3|45203|214054
6|30406|214054
8|35808|214054
1|10201|214054
5|55305|214054
6|51506|214076
1|36901|214076
2|45202|214076
8|15908|214076
4|10204|214076
3|35803|214076
5|55305|214076
7|56507|214076
5|50205|214088
1|30001|214088
7|45207|214088
3|55103|214088
6|03206|214088
2|35802|214088
4|10204|214088
2|40102|214069
8|15908|214069
1|45201|214069
4|50304|214069
5|12305|214069
6|56506|214069
3|36403|214069
3|36903|214094
5|12805|214094
8|45208|214094
4|50804|214094
6|35706|214094
2|10202|214094
1|30401|214094
8|40508|214067
3|36903|214067
2|45202|214067
7|15907|214067
6|56506|214067
5|12305|214067
4|50304|214067
1|36801|214067
8|36908|214071
2|10902|214071
4|45204|214071
3|50803|214071
6|35706|214071
1|10201|214071
5|16005|214071
1|30001|214086
7|15907|214086
8|45208|214086
2|50202|214086
3|10203|214086
5|30405|214086
6|36806|214086
7|37107|214078
3|16503|214078
4|45204|214078
5|50205|214078
1|35801|214078
8|10208|214078
2|06802|214078
5|08105|214059
4|50804|214059
2|45202|214059
1|30401|214059
6|35706|214059
8|10208|214059
7|16007|214059
8|36908|214050
1|15901|214050
4|45204|214050
2|50202|214050
5|35805|214050
3|10203|214050
6|56506|214050
4|16704|214055
5|52005|214055
3|45203|214055
1|10701|214055
8|51808|214055
2|10202|214055
7|37107|214055
6|36806|214055
3|45403|214099
5|15905|214099
6|45206|214099
1|50201|214099
2|35802|214099
8|10208|214099
7|30407|214099
1|08001|214057
8|15908|214057
3|45203|214057
2|50202|214057
4|36104|214057
7|12307|214057
5|55305|214057
7|50207|214096
1|08001|214096
8|45208|214096
6|30406|214096
3|35703|214096
2|10202|214096
5|16005|214096
7|51507|214056
1|36901|214056
4|41204|214056
5|45205|214056
3|10203|214056
8|36108|214056
2|50202|214056
6|56506|214056
8|50208|214073
1|03501|214073
6|45206|214073
5|16005|214073
2|35802|214073
4|10204|214073
7|06607|214073
7|15907|214074
2|10902|214074
8|45208|214074
5|12805|214074
3|35703|214074
6|10206|214074
1|50201|214074
8|15308|214080
2|30002|214080
3|45203|214080
4|55504|214080
6|10206|214080
1|35801|214080
7|50207|214080
5|30405|214080
3|16503|214065
6|45206|214065
5|41505|214065
8|36908|214065
1|35801|214065
7|10207|214065
2|50202|214065
5|15905|214062
4|55504|214062
3|45203|214062
2|10902|214062
1|10201|214062
8|35808|214062
7|50207|214062
6|30406|214062

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment