sort - cut - command

maelamrani

Member
Joined
Jan 3, 2020
Messages
77
Reaction score
7
Credits
450
Hello,
i need sort the lines of file passwd (/etc/passwrd) through " group ID "(order descending) and through" user ID " (order increasing) with cut commandkind regards,
 


You'll want to look up the sort command first.. you'll need to change the delimiter with the -t option because it assumes you're tab spaced instead of using colons like the /etc/passwd does, you'll want to use -V to sort by 'version numbers' (so 128 comes after 13) and you'll want to use -k to specify the column to sort.

Then, i'm not sure what you're needing cut for, unless you're trying to show a portion of the results afterwards.

Edit: this sounds like a homework assignment, so I don't want to give you the full thing, but you'll do something like sort -V -kX -tX /etc/passwd | cut XXXXX (replacing X with the correct values)
 
Hello,
sort -V -t : -rk4 -k3 /etc/passwd | cut -d ':' -f 3,4

but its doesnt sort the user increasing :

978:1
1:1
11:0
7:0
6:0
5:0
0:0

its should be :
1:1
978:1
0:0
5:0
6:0
7:0
11:0

Full result :
65534:65534
1000:1000
999:999
998:996
997:995
996:993
995:990
994:989
993:987
986:986
985:985
984:984
983:983
982:980
981:979
980:978
979:977
193:193
192:192
173:173
172:172
171:171
113:113
107:107
12:100
81:81
992:76
75:75
74:74
72:72
70:70
59:59
14:50
48:48
42:42
32:32
29:29
8:12
4:7
3:4
2:2
978:1
1:1
11:0
7:0
6:0
5:0
0:0
 
found it : sort -t : -k4,4nr -k3,3n /etc/passwd | cut -d ':' -f 3,4
i should place r in the end of the k
thx a lot
 

Staff online

Members online


Top