sort uniq cut sed wc指令入门以及练习

sort

sort是一种非常简单而且非常有用的命令,它将重新排列文本文件里面的行,默认情况下的排序规则:

  • 以数字开头的行将出现在以字母开头的行之前。
  • 以字母表中较早出现的字母开头的行将出现在以字母表后面出现的字母开头的行之前。
  • 以小写字母开头的行将出现在以大写字母开头的行之前。

语法

sort [option] filename or stdin

常用option参数:

-f:忽略大小写的差异,例如 A 与 a 视为编码相同;
-b:忽略最前面的空格符部分;
-M:以月份的名字来排序,例如 JAN, DEC 等等的排序方法;
-n:使用『纯数字』进行排序(默认是以文字型态来排序的);
-r:反向排序;
-u:就是 uniq ,相同的数据中,仅出现一行代表;

uniq

uniq可以取出文件里面的重复的行, 但是这些重复的行必须恩斯相邻的所以在进行去重之前必须对文件进行一个sort排序,以保证重复的行相邻。

语法以及常用参数

uniq [option]

-i   :忽略大小写字符的不同;
-c  :进行计数
-u  :只显示唯一的行

cut

cut可以从文本文件中提取出某一列

语法以及常用参数

cut -d"分隔符" -f"列数" filename

-d  :后面接分隔字符。与 -f 一起使用;
-f  :依据 -d 的分隔字符将一段信息分割成为数段,用 -f 取出第几段的意思;

sed

sed 可以对数据进行搜索和替换

语法

sed ‘s/要被取代的字串/新的字串/g‘

例:把"hello word"里面的每一个小写字母替换成小写字母a

echo "hello word" | sed "s/[a-z]/a/g"
aaaaa aaaa

wc(words count)

统计文件里的行数,单词数,字符数

语法以及常用参数

wc [option]

-l  :仅列出行;
-w  :仅列出多少字(英文单字);
-m  :多少字符;

例:

wc classes.txt
441    3786   19271 classes.txt

测试用例classes.txt

BINF3010	1UGA	LAB	Tue 16-18	BongoK17G7	21	23
BINF6111	1UGA	SEM	Wed 16-18	BUS 115	0	40
BINF9010	1PGA	LAB	Tue 16-18	BongoK17G7	9	9
COMP1000	M11A	LAB	Mon 11-13	FluteME303	25	25
COMP1000	M11B	LAB	Mon 11-13	BongoK17G7	24	24
COMP1000	M13A	LAB	Mon 13-15	BongoK17G7	24	24
COMP1000	M13B	LAB	Mon 13-15	FluteME303	25	25
COMP1000	M15A	LAB	Mon 15-17	Oboe ME304	25	25
COMP1000	T09A	LAB	Tue 09-11	BongoK17G7	24	24
COMP1000	T09B	LAB	Tue 09-11	TablaK17G7	26	26
COMP1000	T13A	LAB	Tue 13-15	BongoK17G7	24	24
COMP1511	F09A	TLB	Fri 09-10	Quad 1045	24	24
COMP1511	F09B	TLB	Fri 09-10	Quad G032	25	25
COMP1511	F11A	TLB	Fri 11-12	Quad G026	24	24
COMP1511	F11B	TLB	Fri 11-12	Quad 1046	25	25
COMP1511	F13A	TLB	Fri 13-14	Newt 306	25	25
COMP1511	F15A	TLB	Fri 15-16	Quad 1045	24	24
COMP1511	H09A	TLB	Thu 09-10	Webst 252	24	24
COMP1511	H09B	TLB	Thu 09-10	Quad G054	24	24
COMP1511	H11A	TLB	Thu 11-12	Quad G044	24	24
COMP1511	H11B	TLB	Thu 11-12	Quad G031	25	25
COMP1511	H13A	TLB	Thu 13-14	Webst 302	24	24
COMP1511	H13B	TLB	Thu 13-14	Webst 251	25	25
COMP1511	H17A	TLB	Thu 17-18	Quad G054	24	24
COMP1511	T16A	TLB	Tue 16-17	Quad G054	24	24
COMP1511	T16B	TLB	Tue 16-17	Webst 302	24	24
COMP1511	T18A	TLB	Tue 18-19	OMB151	24	24
COMP1511	W09A	TLB	Wed 09-10	Quad 1046	24	24
COMP1511	W09B	TLB	Wed 09-10	Quad G027	25	25
COMP1511	W11A	TLB	Wed 11-12	Newt 306	24	24
COMP1511	W11B	TLB	Wed 11-12	ElecEngG04	25	25
COMP1511	W13A	TLB	Wed 13-14	Webst 251	24	24
COMP1511	W13B	TLB	Wed 13-14	Webst 252	24	24
COMP1511	W18A	TLB	Wed 18-19	BUS 219	25	25
COMP1511	W18B	TLB	Wed 18-19	BUS 118	24	24
COMP1521	F13A	TLB	Fri 13-14	Mat 313	24	24
COMP1521	F13B	TLB	Fri 13-14	Webst 250	25	25
COMP1521	F13C	TLB	Fri 13-14	Law 101	25	25
COMP1521	H13A	TLB	Thu 13-14	Gold G03	25	25
COMP1521	H13B	TLB	Thu 13-14	Law 301	25	25
COMP1521	H15A	TLB	Thu 15-16	Webst 250	25	25
COMP1521	H15B	TLB	Thu 15-16	ElecEngG10	24	25
COMP1521	M09A	TLB	Mon 09-10	Gold G01	36	36
COMP1521	M09B	TLB	Mon 09-10	Webst 302	34	34
COMP1521	M11A	TLB	Mon 11-12	Gold G01	36	36
COMP1521	M11B	TLB	Mon 11-12	Webst 302	34	34
COMP1521	M16A	TLB	Mon 16-17	Law 301	25	25
COMP1521	M16B	TLB	Mon 16-17	ElecEngG09	24	25
COMP1521	M16C	TLB	Mon 16-17	ElecEngG10	25	25
COMP1521	M18A	TLB	Mon 18-19	Quad 1045	20	25
COMP1521	M18B	TLB	Mon 18-19	Gold G09	20	24
COMP1521	T09A	TLB	Tue 09-10	Webst 302	35	36
COMP1521	T09B	TLB	Tue 09-10	Webst 251	34	34
COMP1521	T11A	TLB	Tue 11-12	Quad 1045	25	25
COMP1521	T11B	TLB	Tue 11-12	Quad 1048	25	25
COMP1521	T14A	TLB	Tue 14-15	Law 302	25	25
COMP1521	T14B	TLB	Tue 14-15	Quad 1046	24	24
COMP1521	T16A	TLB	Tue 16-17	AinswthG01	25	25
COMP1521	T16B	TLB	Tue 16-17	Ainswth201	25	25
COMP1521	T18A	TLB	Tue 18-19	Law 276	30	36
COMP1521	W11A	TLB	Wed 11-12	AinswthG01	25	25
COMP1521	W11B	TLB	Wed 11-12	Ainswth201	25	25
COMP1521	W13A	TLB	Wed 13-14	ElecEngG10	25	25
COMP1521	W13B	TLB	Wed 13-14	Law 388	25	25
COMP1521	W18A	TLB	Wed 18-19	Gold G09	24	25
COMP1521	W18B	TLB	Wed 18-19	BUS 114	24	25
COMP2041	F09A	TLB	Fri 09-10	ElecEngG09	21	34
COMP2041	F09B	TLB	Fri 09-10	Ainswth201	21	34
COMP2041	F11A	TLB	Fri 11-12	Law 302	24	34
COMP2041	F11B	TLB	Fri 11-12	Law 301	28	34
COMP2041	F13A	TLB	Fri 13-14	ElecEngG10	29	34
COMP2041	F13B	TLB	Fri 13-14	Quad G044	32	34
COMP2041	H09A	TLB	Thu 09-10	ElecEngG03	20	34
COMP2041	H09B	TLB	Thu 09-10	Quad G045	20	34
COMP2041	H11A	TLB	Thu 11-12	ElecEngG09	27	34
COMP2041	H11B	TLB	Thu 11-12	Webst 250	14	34
COMP2041	H13A	TLB	Thu 13-14	AinswthG01	28	34
COMP2041	H13B	TLB	Thu 13-14	ElecEngG04	32	34
COMP2041	T15A	TLB	Tue 15-16	AinswthG01	14	34
COMP2041	W09A	TLB	Wed 09-10	Ainswth201	19	34
COMP2041	W09B	TLB	Wed 09-10	Webst 302	9	34
COMP2041	W11A	TLB	Wed 11-12	CivEng G6	24	34
COMP2041	W11B	TLB	Wed 11-12	Webst 302	20	34
COMP2041	W13A	TLB	Wed 13-14	ElecEngG03	31	34
COMP2041	W15A	TLB	Wed 15-16	Quad G031	26	34
COMP2041	W17A	TLB	Wed 17-18	Ainswth201	25	34
COMP2121	F09A	LAB	Fri 09-11	ElecEng225	12	30
COMP2121	F11A	LAB	Fri 11-13	ElecEng225	29	30
COMP2121	F13A	LAB	Fri 13-15	ElecEng225	28	30
COMP2121	F15A	LAB	Fri 15-17	ElecEng225	0	30
COMP2121	H10A	LAB	Thu 10-12	ElecEng225	29	30
COMP2121	H14A	LAB	Thu 14-16	ElecEng225	30	30
COMP2121	H16A	LAB	Thu 16-18	ElecEng225	29	30
COMP2511	F09A	TLB	Fri 09-10	BUS 118	21	24
COMP2511	F09B	TLB	Fri 09-10	BUS 114	22	26
COMP2511	F11A	TLB	Fri 11-12	Quad G040	23	24
COMP2511	F11B	TLB	Fri 11-12	Webst 302	24	26
COMP2511	F13A	TLB	Fri 13-14	Law 163	19	24
COMP2511	F13B	TLB	Fri 13-14	Law 201	20	26
COMP2511	H11A	TLB	Thu 11-12	Col LG02	24	24
COMP2511	H11B	TLB	Thu 11-12	Gold G05	22	24
COMP2511	H13A	TLB	Thu 13-14	Law 275	24	24
COMP2511	H13B	TLB	Thu 13-14	Law 202	25	25
COMP2511	H15A	TLB	Thu 15-16	Sqhouse205	24	24
COMP2511	H15B	TLB	Thu 15-16	Sqhouse215	24	24
COMP2511	T18A	TLB	Tue 18-19	Quad G046	24	24
COMP2511	W09A	TLB	Wed 09-10	BUS 114	21	24
COMP2511	W09B	TLB	Wed 09-10	ElecEngG10	24	26
COMP2511	W11A	TLB	Wed 11-12	SEB B24	24	24
COMP2511	W11B	TLB	Wed 11-12	Law 301	26	26
COMP2511	W13A	TLB	Wed 13-14	Law 303	24	24
COMP2511	W13B	TLB	Wed 13-14	Col LG02	26	26
COMP2511	W15A	TLB	Wed 15-16	Quad 1047	24	24
COMP2511	W15B	TLB	Wed 15-16	RedC M010	25	26
COMP2521	F09A	TLB	Fri 09-10	Webst 252	24	24
COMP2521	F09B	TLB	Fri 09-10	Ainswth101	24	25
COMP2521	F11A	TLB	Fri 11-12	Quad 1047	25	25
COMP2521	F11B	TLB	Fri 11-12	Quad 1048	24	25
COMP2521	H09A	TLB	Thu 09-10	Quad 1046	25	25
COMP2521	H09B	TLB	Thu 09-10	Quad 1047	24	25
COMP2521	H15A	TLB	Thu 15-16	Newt 307	23	24
COMP2521	H15B	TLB	Thu 15-16	Sqhouse214	24	24
COMP2521	M11A	TLB	Mon 11-12	Quad G032	24	24
COMP2521	M13A	TLB	Mon 13-14	Webst 250	24	24
COMP2521	M15A	TLB	Mon 15-16	Newt 307	0	24
COMP2521	T09A	TLB	Tue 09-10	Newt 307	23	24
COMP2521	T09B	TLB	Tue 09-10	Gold G05	23	24
COMP2521	T11A	TLB	Tue 11-12	Newt 307	23	24
COMP2521	T11B	TLB	Tue 11-12	RedC 4037	25	25
COMP2521	T13A	TLB	Tue 13-14	Quad G053	36	36
COMP2521	T13B	TLB	Tue 13-14	Webst 250	34	34
COMP2521	W09A	TLB	Wed 09-10	RedC 3037	20	25
COMP2521	W09B	TLB	Wed 09-10	Quad G052	24	25
COMP3151	H12A	TUT	Thu 12-14	Quad G045	18	20
COMP3151	H14A	TUT	Thu 14-16	Quad 1042	8	20
COMP3151	H16A	TUT	Thu 16-18	Quad 1042	6	20
COMP3331	F09A	LAB	Fri 09-11	Drum K17B8	14	24
COMP3331	H10A	LAB	Thu 10-12	BongoK17G7	8	24
COMP3331	H10B	LAB	Thu 10-12	TablaK17G7	11	24
COMP3331	H12A	LAB	Thu 12-14	FluteME303	5	24
COMP3331	H12B	LAB	Thu 12-14	Oboe ME304	0	24
COMP3331	H16A	LAB	Thu 16-18	StringsME3	3	24
COMP3331	H16B	LAB	Thu 16-18	BrassME305	1	24
COMP3331	M18A	LAB	Mon 18-20	BongoK17G7	14	24
COMP3331	M18B	LAB	Mon 18-20	TablaK17G7	16	24
COMP3331	T10A	LAB	Tue 10-12	FluteME303	14	24
COMP3331	T10B	LAB	Tue 10-12	Oboe ME304	14	25
COMP3331	T12A	LAB	Tue 12-14	StringsME3	22	24
COMP3331	T12B	LAB	Tue 12-14	BrassME305	21	34
COMP3331	T14A	LAB	Tue 14-16	SitarME306	7	24
COMP3331	T14B	LAB	Tue 14-16	KoraME307	8	24
COMP3331	W16A	LAB	Wed 16-18	SitarME306	2	24
COMP3331	W16B	LAB	Wed 16-18	KoraME307	7	24
COMP3331	W18A	LAB	Wed 18-20	BongoK17G7	4	24
COMP3331	W18B	LAB	Wed 18-20	TablaK17G7	9	26
COMP3411	H14A	TUT	Thu 14-15	Quad 1049	7	20
COMP3411	H15A	TUT	Thu 15-16	Quad 1049	4	20
COMP3411	H16A	TUT	Thu 16-17	Quad 1049	4	20
COMP3411	M16A	TUT	Mon 16-17	Quad 1043	6	25
COMP3411	M17A	TUT	Mon 17-18	Quad 1043	3	25
COMP3411	T12A	TUT	Tue 12-13	Quad 1042	13	22
COMP3411	T13A	TUT	Tue 13-14	Quad 1042	10	22
COMP3411	T14A	TUT	Tue 14-15	Quad 1042	0	22
COMP3411	T15A	TUT	Tue 15-16	Quad 1042	10	22
COMP3411	T16A	TUT	Tue 16-17	Quad 1042	5	22
COMP3411	W12A	TUT	Wed 12-13	Quad 1042	10	22
COMP3411	W13A	TUT	Wed 13-14	Quad 1042	0	22
COMP3411	W14A	TUT	Wed 14-15	Quad 1042	14	22
COMP3411	W15A	TUT	Wed 15-16	Quad 1042	4	22
COMP3411	W16A	TUT	Wed 16-17	Quad 1042	4	22
COMP3421	M14A	TUT	Mon 14-15	Gold G05	18	24
COMP3421	M15A	TUT	Mon 15-16	Gold G05	0	24
COMP3421	M16A	TUT	Mon 16-17	Gold G01	15	30
COMP3421	M17A	TUT	Mon 17-18	Gold G01	0	30
COMP3421	M18A	TUT	Mon 18-19	Gold G01	0	30
COMP3421	M19A	TUT	Mon 19-20	Gold G01	0	30
COMP3421	T13A	TUT	Tue 13-14	Quad G054	0	24
COMP3421	T14A	TUT	Tue 14-15	Quad G045	26	30
COMP3421	T18A	TUT	Tue 18-19	Quad G054	21	24
COMP3421	W16A	TUT	Wed 16-17	Quad G031	21	24
COMP3421	W17A	TUT	Wed 17-18	Webst 252	0	24
COMP3421	W18A	TUT	Wed 18-19	Webst 251	0	30
COMP3900	F11A	LAB	Fri 11-13	Drum K17B8	8	20
COMP3900	F13A	LAB	Fri 13-15	Drum K17B8	9	20
COMP3900	M11A	LAB	Mon 11-13	Drum K17B8	4	20
COMP3900	M13A	LAB	Mon 13-15	Drum K17B8	6	20
COMP3900	M15A	LAB	Mon 15-17	Drum K17B8	8	20
COMP3900	T09A	LAB	Tue 09-11	Drum K17B8	4	20
COMP3900	T11A	LAB	Tue 11-13	Drum K17B8	12	20
COMP3900	T13A	LAB	Tue 13-15	Drum K17B8	7	20
COMP3900	W09A	LAB	Wed 09-11	Drum K17B8	6	20
COMP3900	W11A	LAB	Wed 11-13	Drum K17B8	12	20
COMP4336	F14A	LAB	Fri 14-16	LyreK17G12	6	20
COMP4336	F16A	LAB	Fri 16-18	LyreK17G12	0	18
COMP4336	H14A	LAB	Thu 14-16	LyreK17G12	6	20
COMP4336	H16A	LAB	Thu 16-18	LyreK17G12	5	20
COMP4336	M16A	LAB	Mon 16-18	LyreK17G12	7	20
COMP4336	T14A	LAB	Tue 14-16	LyreK17G12	5	20
COMP4336	T16A	LAB	Tue 16-18	LyreK17G12	2	20
COMP4336	W14A	LAB	Wed 14-16	LyreK17G12	3	20
COMP4511	M14A	LAB	Mon 14-17	CHIK17G13	0	10
COMP4511	T14A	LAB	Tue 14-17	TBA	0	10
COMP6441	F09A	LAB	Fri 09-11	CybSK17G11	3	20
COMP6441	F11A	LAB	Fri 11-13	CybSK17G11	4	20
COMP6441	F13A	LAB	Fri 13-15	CybSK17G11	1	20
COMP6441	F14A	LAB	Fri 14-16	ElecEngG09	0	30
COMP6441	F15A	LAB	Fri 15-17	CybSK17G11	0	20
COMP6441	H09A	LAB	Thu 09-11	CybSK17G11	2	20
COMP6441	H11A	LAB	Thu 11-13	CybSK17G11	3	20
COMP6441	H13A	LAB	Thu 13-15	CybSK17G11	0	20
COMP6441	H15A	LAB	Thu 15-17	CybSK17G11	2	20
COMP6441	H15B	LAB	Thu 15-17	OMB151	0	20
COMP6441	H17A	LAB	Thu 17-19	CybSK17G11	1	20
COMP6441	W09B	LAB	Wed 09-11	RedC 4034	0	24
COMP6441	W09C	LAB	Wed 09-11	RedC 1041	0	24
COMP6441	W11A	LAB	Wed 11-13	CybSK17G11	2	20
COMP6441	W13A	LAB	Wed 13-15	CybSK17G11	1	20
COMP6441	W13B	LAB	Wed 13-15	AinswthG01	0	24
COMP6441	W15A	LAB	Wed 15-17	CybSK17G11	4	20
COMP6441	W16A	LAB	Wed 16-18	Ainswth101	0	50
COMP6441	W17A	LAB	Wed 17-19	CybSK17G11	3	20
COMP6441	W09A	LAB	Wed 09-11	CybSK17G11	17	20
COMP6447	M14A	LAB	Mon 14-16	CybSK17G11	0	10
COMP6447	M16A	LAB	Mon 16-18	CybSK17G11	0	10
COMP6447	T10A	LAB	Tue 10-12	CybSK17G11	0	10
COMP6447	T12A	LAB	Tue 12-14	CybSK17G11	1	10
COMP6447	T14A	LAB	Tue 14-16	CybSK17G11	0	10
COMP6447	T16A	SEM	Tue 16-17	Quad G042	1	10
COMP6447	T17A	SEM	Tue 17-18	Quad G042	0	10
COMP6447	W12A	SEM	Wed 12-13	Quad G042	0	10
COMP6447	W13A	SEM	Wed 13-14	Quad G042	0	10
COMP6447	W14A	SEM	Wed 14-15	Quad G042	0	10
COMP6771	F10A	TUT	Fri 10-11	OMB151	9	30
COMP6771	F11A	TUT	Fri 11-12	Quad G045	6	30
COMP6771	F14A	TUT	Fri 14-15	Quad G042	6	22
COMP6771	F15A	TUT	Fri 15-16	Quad G042	0	22
COMP6771	F16A	TUT	Fri 16-17	Quad G027	9	30
COMP6771	F17A	TUT	Fri 17-18	OMB151	14	30
COMP6771	H10A	TUT	Thu 10-11	Webst 252	10	24
COMP6771	H11A	TUT	Thu 11-12	Webst 252	5	24
COMP6771	H12A	TUT	Thu 12-13	Quad G044	8	24
COMP6771	H13A	TUT	Thu 13-14	Webst 252	4	24
COMP6771	H14A	TUT	Thu 14-15	Mat 309	19	30
COMP6771	H15A	TUT	Thu 15-16	Quad G055	11	22
COMP6771	H16A	TUT	Thu 16-17	Quad G055	9	22
COMP6771	H17A	TUT	Thu 17-18	Quad G055	11	22
COMP6771	W16A	TUT	Wed 16-17	Quad G042	12	22
COMP6771	W17A	TUT	Wed 17-18	Quad G026	12	30
COMP6841	F09A	LAB	Fri 09-11	CybSK17G11	0	10
COMP6841	F11A	LAB	Fri 11-13	CybSK17G11	0	10
COMP6841	F13A	LAB	Fri 13-15	CybSK17G11	0	10
COMP6841	F14A	LAB	Fri 14-16	ElecEngG09	0	30
COMP6841	F15A	LAB	Fri 15-17	CybSK17G11	1	10
COMP6841	H09A	LAB	Thu 09-11	CybSK17G11	1	10
COMP6841	H11A	LAB	Thu 11-13	CybSK17G11	0	10
COMP6841	H13A	LAB	Thu 13-15	CybSK17G11	0	10
COMP6841	H15A	LAB	Thu 15-17	CybSK17G11	0	10
COMP6841	H15B	LAB	Thu 15-17	OMB151	0	30
COMP6841	H17A	LAB	Thu 17-19	CybSK17G11	1	10
COMP6841	W09A	LAB	Wed 09-11	CybSK17G11	1	10
COMP6841	W09B	LAB	Wed 09-11	RedC 4034	0	32
COMP6841	W09C	LAB	Wed 09-11	RedC 1041	0	38
COMP6841	W11A	LAB	Wed 11-13	CybSK17G11	1	10
COMP6841	W13A	LAB	Wed 13-15	CybSK17G11	1	10
COMP6841	W13B	LAB	Wed 13-15	AinswthG01	0	38
COMP6841	W15A	LAB	Wed 15-17	CybSK17G11	2	10
COMP6841	W16A	LAB	Wed 16-18	Ainswth101	0	38
COMP6841	W17A	LAB	Wed 17-19	CybSK17G11	0	10
COMP9044	F09A	TLB	Fri 09-10	ElecEngG09	6	34
COMP9044	F09B	TLB	Fri 09-10	Ainswth201	4	34
COMP9044	F11A	TLB	Fri 11-12	Law 302	1	34
COMP9044	F11B	TLB	Fri 11-12	Law 301	5	34
COMP9044	F13A	TLB	Fri 13-14	ElecEngG10	4	34
COMP9044	F13B	TLB	Fri 13-14	Quad G044	2	34
COMP9044	H09A	TLB	Thu 09-10	ElecEngG03	8	34
COMP9044	H09B	TLB	Thu 09-10	Quad G045	6	34
COMP9044	H11A	TLB	Thu 11-12	ElecEngG09	6	34
COMP9044	H11B	TLB	Thu 11-12	Webst 250	4	34
COMP9044	H13A	TLB	Thu 13-14	AinswthG01	6	34
COMP9044	H13B	TLB	Thu 13-14	ElecEngG04	2	34
COMP9044	T15A	TLB	Tue 15-16	AinswthG01	20	34
COMP9044	W09A	TLB	Wed 09-10	Ainswth201	10	34
COMP9044	W09B	TLB	Wed 09-10	Webst 302	12	34
COMP9044	W11A	TLB	Wed 11-12	CivEng G6	9	34
COMP9044	W11B	TLB	Wed 11-12	Webst 302	4	34
COMP9044	W13A	TLB	Wed 13-14	ElecEngG03	3	34
COMP9044	W15A	TLB	Wed 15-16	Quad G031	8	34
COMP9044	W17A	TLB	Wed 17-18	Ainswth201	9	34
COMP9154	H12A	TUT	Thu 12-14	Quad G045	1	10
COMP9154	H14A	TUT	Thu 14-16	Quad 1042	1	10
COMP9154	H16A	TUT	Thu 16-18	Quad 1042	0	10
COMP9311	H09A	LAB	Thu 09-11	Drum K17B8	10	24
COMP9311	H11A	LAB	Thu 11-13	Drum K17B8	12	24
COMP9311	M15A	LAB	Mon 15-17	FluteME303	21	24
COMP9311	M17A	LAB	Mon 17-19	Drum K17B8	15	24
COMP9311	T11A	LAB	Tue 11-13	BongoK17G7	21	24
COMP9311	T11B	LAB	Tue 11-13	TablaK17G7	17	24
COMP9311	T13A	LAB	Tue 13-15	TablaK17G7	24	24
COMP9313	H13A	LAB	Thu 13-15	Drum K17B8	7	24
COMP9313	H18A	LAB	Thu 18-20	SitarME306	1	25
COMP9313	H18B	LAB	Thu 18-20	KoraME307	6	24
COMP9313	M14A	LAB	Mon 14-16	ViolaME302	5	18
COMP9313	M14B	LAB	Mon 14-16	CelloME302	4	18
COMP9313	M16A	LAB	Mon 16-18	ViolaME302	2	18
COMP9313	M16B	LAB	Mon 16-18	CelloME302	3	18
COMP9313	M16C	LAB	Mon 16-18	BugleME305	0	18
COMP9313	M18A	LAB	Mon 18-20	KoraME307	3	18
COMP9313	T17A	LAB	Tue 17-19	Drum K17B8	1	24
COMP9313	W16A	LAB	Wed 16-18	FluteME303	1	25
COMP9313	W16B	LAB	Wed 16-18	Oboe ME304	0	25
COMP9313	W18A	LAB	Wed 18-20	Drum K17B8	1	24
COMP9319	H13A	TUT	Thu 13-14	Gold G04	3	18
COMP9319	H14A	TUT	Thu 14-15	Gold G04	9	18
COMP9319	H15A	TUT	Thu 15-16	Gold G04	0	18
COMP9319	H16A	TUT	Thu 16-17	Gold G04	0	18
COMP9319	H17A	TUT	Thu 17-18	Gold G04	9	18
COMP9319	T16A	TUT	Tue 16-17	Gold G04	14	18
COMP9319	T17A	TUT	Tue 17-18	Gold G04	11	18
COMP9319	W12A	TUT	Wed 12-13	Gold G04	6	18
COMP9319	W13A	TUT	Wed 13-14	Gold G04	0	18
COMP9319	W14A	TUT	Wed 14-15	Gold G04	0	18
COMP9319	W15A	TUT	Wed 15-16	Gold G04	14	18
COMP9319	W16A	TUT	Wed 16-17	Gold G04	7	18
COMP9319	W17A	TUT	Wed 17-18	Gold G04	10	18
COMP9322	M13A	LAB	Mon 13-14	TablaK17G7	0	24
COMP9322	M14A	LAB	Mon 14-15	Oboe ME304	9	24
COMP9322	M15A	LAB	Mon 15-16	TablaK17G7	0	24
COMP9322	M16A	LAB	Mon 16-17	SitarME306	10	24
COMP9322	H15A	TUT	Thu 15-16	Mat 107	10	25
COMP9322	H16A	TUT	Thu 16-17	Mat 107	0	25
COMP9322	H17A	TUT	Thu 17-18	Mat 102	9	25
COMP9331	F09A	LAB	Fri 09-11	Drum K17B8	8	24
COMP9331	H10A	LAB	Thu 10-12	BongoK17G7	15	24
COMP9331	H10B	LAB	Thu 10-12	TablaK17G7	11	24
COMP9331	H12A	LAB	Thu 12-14	FluteME303	19	24
COMP9331	H12B	LAB	Thu 12-14	Oboe ME304	22	24
COMP9331	H16A	LAB	Thu 16-18	StringsME3	20	24
COMP9331	H16B	LAB	Thu 16-18	BrassME305	21	24
COMP9331	M18A	LAB	Mon 18-20	BongoK17G7	7	24
COMP9331	M18B	LAB	Mon 18-20	TablaK17G7	5	24
COMP9331	T10A	LAB	Tue 10-12	FluteME303	9	24
COMP9331	T10B	LAB	Tue 10-12	Oboe ME304	3	24
COMP9331	T12A	LAB	Tue 12-14	StringsME3	8	24
COMP9331	T12B	LAB	Tue 12-14	BrassME305	10	24
COMP9331	T14A	LAB	Tue 14-16	SitarME306	16	24
COMP9331	T14B	LAB	Tue 14-16	KoraME307	15	24
COMP9331	W16A	LAB	Wed 16-18	SitarME306	22	24
COMP9331	W16B	LAB	Wed 16-18	KoraME307	17	24
COMP9331	W18A	LAB	Wed 18-20	BongoK17G7	19	24
COMP9331	W18B	LAB	Wed 18-20	TablaK17G7	13	24
COMP9332	M14A	LAB	Mon 14-16	Horn ME305	9	10
COMP9332	M16A	LAB	Mon 16-18	TablaK17G7	6	9
COMP9336	F14A	LAB	Fri 14-16	LyreK17G12	13	20
COMP9336	F16A	LAB	Fri 16-18	LyreK17G12	0	18
COMP9336	H14A	LAB	Thu 14-16	LyreK17G12	13	20
COMP9336	H16A	LAB	Thu 16-18	LyreK17G12	12	20
COMP9336	M16A	LAB	Mon 16-18	LyreK17G12	9	20
COMP9336	T14A	LAB	Tue 14-16	LyreK17G12	11	20
COMP9336	T16A	LAB	Tue 16-18	LyreK17G12	14	20
COMP9336	W14A	LAB	Wed 14-16	LyreK17G12	13	20
COMP9414	H14A	TUT	Thu 14-15	Quad 1049	13	20
COMP9414	H15A	TUT	Thu 15-16	Quad 1049	16	20
COMP9414	H16A	TUT	Thu 16-17	Quad 1049	16	20
COMP9414	M16A	TUT	Mon 16-17	Quad 1043	22	26
COMP9414	M17A	TUT	Mon 17-18	Quad 1043	24	26
COMP9414	T12A	TUT	Tue 12-13	Quad 1042	8	22
COMP9414	T13A	TUT	Tue 13-14	Quad 1042	12	22
COMP9414	T14A	TUT	Tue 14-15	Quad 1042	0	22
COMP9414	T15A	TUT	Tue 15-16	Quad 1042	12	22
COMP9414	T16A	TUT	Tue 16-17	Quad 1042	17	22
COMP9414	W12A	TUT	Wed 12-13	Quad 1042	12	22
COMP9414	W13A	TUT	Wed 13-14	Quad 1042	0	22
COMP9414	W14A	TUT	Wed 14-15	Quad 1042	8	22
COMP9414	W15A	TUT	Wed 15-16	Quad 1042	18	22
COMP9414	W16A	TUT	Wed 16-17	Quad 1042	18	22
COMP9415	M14A	TUT	Mon 14-15	Gold G05	6	24
COMP9415	M15A	TUT	Mon 15-16	Gold G05	0	24
COMP9415	M16A	TUT	Mon 16-17	Gold G01	10	30
COMP9415	M17A	TUT	Mon 17-18	Gold G01	0	30
COMP9415	M18A	TUT	Mon 18-19	Gold G01	0	30
COMP9415	M19A	TUT	Mon 19-20	Gold G01	0	30
COMP9415	T13A	TUT	Tue 13-14	Quad G054	0	24
COMP9415	T14A	TUT	Tue 14-15	Quad G045	4	30
COMP9415	T18A	TUT	Tue 18-19	Quad G054	3	24
COMP9415	W16A	TUT	Wed 16-17	Quad G031	3	30
COMP9415	W17A	TUT	Wed 17-18	Webst 252	0	24
COMP9415	W18A	TUT	Wed 18-19	Webst 251	0	30
COMP9417	F10A	TUT	Fri 10-11	ElecEngG04	5	35
COMP9417	F10B	TUT	Fri 10-11	BUS 118	9	28
COMP9417	F11A	TUT	Fri 11-12	Quad 1042	9	22
COMP9417	F11B	TUT	Fri 11-12	BUS 118	10	28
COMP9417	F12A	TUT	Fri 12-13	Quad 1042	9	22
COMP9417	F12B	TUT	Fri 12-13	BUS 118	5	28
COMP9417	F13A	TUT	Fri 13-14	ElecEngG04	12	30
COMP9417	F13B	TUT	Fri 13-14	BUS 118	9	28
COMP9417	F16A	TUT	Fri 16-17	ElecEngG09	0	20
COMP9417	F16B	TUT	Fri 16-17	Quad G048	0	20
COMP9417	F17A	TUT	Fri 17-18	ElecEngG09	3	20
COMP9417	F17B	TUT	Fri 17-18	Quad G027	1	20
COMP9417	H10A	TUT	Thu 10-11	Quad G045	10	30
COMP9417	H11A	TUT	Thu 11-12	Quad G045	6	30
COMP9417	H14A	TUT	Thu 14-15	ElecEngG10	0	24
COMP9417	H15A	TUT	Thu 15-16	Quad 1048	0	30
COMP9417	H16A	TUT	Thu 16-17	Quad 1048	10	30
COMP9417	H17A	TUT	Thu 17-18	Quad G027	7	20
COMP9417	T10A	TUT	Tue 10-11	Quad 1049	0	20
COMP9417	T11A	TUT	Tue 11-12	Quad 1049	13	20
COMP9417	T12A	TUT	Tue 12-13	Quad G032	10	20
COMP9417	T13A	TUT	Tue 13-14	Quad 1049	10	20
COMP9417	T14A	TUT	Tue 14-15	Quad 1049	11	20
COMP9417	T15A	TUT	Tue 15-16	Quad 1049	8	20
COMP9417	T16A	TUT	Tue 16-17	Quad 1049	5	20
COMP9417	W12A	TUT	Wed 12-13	Quad G055	7	22
COMP9417	W13A	TUT	Wed 13-14	ElecEngG09	17	30
COMP9417	W14A	TUT	Wed 14-15	Quad G046	7	22
COMP9417	W15A	TUT	Wed 15-16	Quad G055	1	22
COMP9417	W16A	TUT	Wed 16-17	Quad G055	4	22
COMP9900	F11A	LAB	Fri 11-13	Drum K17B8	12	15
COMP9900	F13A	LAB	Fri 13-15	Drum K17B8	8	15
COMP9900	M11A	LAB	Mon 11-13	Drum K17B8	3	15
COMP9900	M13A	LAB	Mon 13-15	Drum K17B8	14	15
COMP9900	M15A	LAB	Mon 15-17	Drum K17B8	8	15
COMP9900	T09A	LAB	Tue 09-11	Drum K17B8	15	15
COMP9900	T11A	LAB	Tue 11-13	Drum K17B8	8	15
COMP9900	T13A	LAB	Tue 13-15	Drum K17B8	6	15
COMP9900	W09A	LAB	Wed 09-11	Drum K17B8	14	15
COMP9900	W11A	LAB	Wed 11-13	Drum K17B8	4	15
ENGG1811	F11A	LAB	Fri 11-13	OrganPhysU	16	20
ENGG1811	F11B	LAB	Fri 11-13	ClavierPhU	15	20
ENGG1811	F13A	LAB	Fri 13-15	OrganPhysU	20	20
ENGG1811	F13B	LAB	Fri 13-15	ClavierPhU	20	20
ENGG1811	H09A	LAB	Thu 09-11	OrganPhysU	19	20
ENGG1811	H09B	LAB	Thu 09-11	ClavierPhU	18	20
ENGG1811	H11A	LAB	Thu 11-13	OrganPhysU	20	20
ENGG1811	H11B	LAB	Thu 11-13	ClavierPhU	20	20
ENGG1811	H13A	LAB	Thu 13-15	OrganPhysU	20	20
ENGG1811	H13B	LAB	Thu 13-15	ClavierPhU	19	20
ENGG1811	H15A	LAB	Thu 15-17	OrganPhysU	20	20
ENGG1811	H15B	LAB	Thu 15-17	ClavierPhU	19	20
ENGG1811	W15A	LAB	Wed 15-17	OrganPhysU	20	20
ENGG1811	W15B	LAB	Wed 15-17	ClavierPhU	20	20

Q1:计算有多少门课程

cut -f1 classes.txt | wc -l
     441

Q2:计算有多少门不同的课程

cut -f1 classes.txt | sort | uniq |  wc -l
      35

Q3:计算出现次数最多的课程并计算出现了多少次

cut -f1 classes.txt | sort | uniq -c | sort -n | tail -1
  31 COMP1521

Q4:计算以"COMP"开头的课程使用最多的教室(不计算LAB教室)并计算使用次数

egrep ‘COMP‘ classes.txt | egrep -v ‘LAB‘ | cut -f5 | sort |uniq -c | sort -nr| head -n1
  26 Quad 1042

Q5:计算哪一天的哪一个时间(以开始时间为标准)课程最多

cut -f4 classes.txt | cut -d"-" -f1 | sort | uniq -c| sort -n | tail -1
  20 Fri 11

原文地址:https://www.cnblogs.com/dxh1015/p/11041868.html

时间: 2024-11-12 02:15:19

sort uniq cut sed wc指令入门以及练习的相关文章

sort,uniq,cut,wc命令详解

sortsort 命令对 File 参数指定的文件中的行排序,并将结果写到标准输出.如果 File 参数指定多个文件,那么 sort 命令将这些文件连接起来,并当作一个文件进行排序. sort语法 sort [-fbMnrtuk] [file or stdin]选项与参数:-f  :忽略大小写的差异,例如 A 与 a 视为编码相同:-b  :忽略最前面的空格符部分:-M  :以月份的名字来排序,例如 JAN, DEC 等等的排序方法:-n  :使用『纯数字』进行排序(默认是以文字型态来排序的):

linux sort,uniq,cut,wc.

文章转自 http://www.cnblogs.com/ggjucheng/archive/2013/01/13/2858385.html sort sort 命令对 File 参数指定的文件中的行排序,并将结果写到标准输出.如果 File 参数指定多个文件,那么 sort 命令将这些文件连接起来,并当作一个文件进行排序. sort语法 [[email protected] ~]# sort [-fbMnrtuk] [file or stdin] 选项与参数: -f :忽略大小写的差异,例如 A

linux sort uniq cut wc命令详解

sort sort 命令对 File 参数指定的文件中的行排序,并将结果写到标准输出.如果 File 参数指定多个文件,那么 sort 命令将这些文件连接起来,并当作一个文件进行排序. sort语法 [[email protected] ~]# sort [-fbMnrtuk] [file or stdin] 选项与参数: -f :忽略大小写的差异,例如 A 与 a 视为编码相同: -b :忽略最前面的空格符部分: -M :以月份的名字来排序,例如 JAN, DEC 等等的排序方法: -n :使

Ubuntu 14.10 下sort,uniq,cut,wc命令详解

sort sort 命令对 File 参数指定的文件中的行排序,并将结果写到标准输出.如果 File 参数指定多个文件,那么 sort 命令将这些文件连接起来,并当作一个文件进行排序. sort语法 [[email protected] ~]# sort [-fbMnrtuk] [file or stdin] 选项与参数: -f :忽略大小写的差异,例如 A 与 a 视为编码相同: -b :忽略最前面的空格符部分: -M :以月份的名字来排序,例如 JAN, DEC 等等的排序方法: -n :使

shell 文本处理的几个命名sed,awk,sort,uniq,cut

文本处理 Cat命令 1)  拼接文件:纵向拼接,不是横向拼接 [email protected]:~# cat list list2 line2 line3 line4 line5 line5 line6 line7 total 32K lrwxrwxrwx 1 root root   12 Jan  4 11:30 backup -> /data/backup -rw-r--r-- 1 root root   46 Apr  1 13:18 list -rw-r--r-- 1 root ro

[linux] grep awk sort uniq学习

grep的-A-B-选项详解grep能找出带有关键字的行,但是工作中有时需要找出该行前后的行,下面是解释1. grep -A1 keyword filename找出filename中带有keyword的行,输出中除显示该行外,还显示之后的一行(After 1)2. grep -B1 keyword filename找出filename中带有keyword的行,输出中除显示该行外,还显示之前的一行(Before 1)3. grep -1 keyword filename找出filename中带有k

05,文本处理cat more less head tail sort uniq wc tr grep cut jion sed awk ok

文本处理cat more less head tail sort uniq grep cut jion sed awk ################################################ cat:concatenate files and print on the standard output 显示文件内容到标准输出(显示器) -e:显示最后一个结尾的字符 -n:显示行编号 [[email protected] ~]# cat -n /etc/shells 1  

文本处理命令- cat more less cut wc sort uniq

文本处理命令 cat more less cut wc sort uniq 1.cat  cat主要功能:1.一次显示整个文件. cat filename2.从键盘创建一个文件. cat > filename   (只能创建新文件,不能编辑已有文件). 1 [[email protected] ~]$ cat > test.txt 2 this is a test for cat command.^[[D 3 a 4 b 5 cc 6 de 其中^[[D是向左的箭头,本想回退一格编辑,但很可惜

linux基础篇07,linux文本处理cat more less head tail sort uniq grep cut jion sed awk

文本处理cat more less head tail sort uniq grep cut jion sed awk ################################################ cat:concatenate files and print on the standard output 显示文件内容到标准输出(显示器) -e:显示最后一个结尾的字符 -n:显示行编号 [[email protected] ~]# cat -n /etc/shells 1