-
Notifications
You must be signed in to change notification settings - Fork 4
Expand file tree
/
Copy pathRedhat.-.Day8(Sorting).txt
More file actions
101 lines (83 loc) · 1.67 KB
/
Copy pathRedhat.-.Day8(Sorting).txt
File metadata and controls
101 lines (83 loc) · 1.67 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
sort command allow us to sort the content of file.By default alphabetical order
cat > test_file
Sanjay, 30
Sarvan, 32
Vikram, 12
Albert, 19
---------
sort test_file
Albert, 19
Sanjay, 30
Sarvan, 32
Vikram, 12
----------------------------------------------
How to sort by column by linux
sort -k2 test_file
Vikram, 12
Albert, 19
Sanjay, 30
Sarvan, 32
-------------------------------------------
How to sort in reverse order in linux
sort -r -k2 test_file
Sarvan, 32
Sanjay, 30
Albert, 19
Vikram, 12
------------------------------------------------
How to merge file with sort
cat sample_file
Sodi, 45
Vakar, 34
---------
-m option allow us merge files in single file.
sort -m sample_file test_file
Sanjay, 30
Sarvan, 32
Sodi, 45
Vakar, 34
Vikram, 12
Albert, 19
cat demo_file
Sanjay, 30
Sarvan, 32
Sodi, 45
Vakar, 34
Vikram, 12
Albert, 19
------------------------------------------------
How to save sort output file
By default sort command will print out on standard ouput.Nothing is going to write in file.To save output in file either use -o option
or use redirect
sort -r demo_file > new_file
or
sort -r demo_file -o new_file
---------------------------------------------------
How to sort number in linux
Use -n option to sort based on number.Create a simple file with numbers and use default sort order.
It sorted alphabetically
cat > number_file
5
56
7
4
6
sort number_file
4
5
56
6
7
To sort this based on number -n optio
sort -n number_file
4
5
6
7
56
------------------------------------------------
How to sort files by size
You can sort files by size with use of sort command
sort ls -l | sort -k5
---------------------------------------------------
man sort