Portál AbcLinuxu, 12. května 2025 09:21
Dobry den, uz od vcerejska se snazim pochopit, co presne dela parametr --key (-k) u utility sort.
Nasel jsem napriklad tento priklad, ale z nej to take nechapu:
$ cat data.csv 1020,Aglája,Vopajšlíková,BIT 3r 1021,Josef,Vonásek,MGM 2r $ sort -t, -k4.5gr,4 -k3,3 -k2,2 data.csv
Mohl by mi to prosim nekdo strucne srozumitelne vysvetlit? Byl bych moc vdecny. Dekuji.
Viz manual:
-k, --key=POS1[,POS2] start a key at POS1, end it at POS2 (origin 1)
POS is F[.C][OPTS], where F is the field number and C the character position in the field; both are origin 1. If neither -t nor -b is in effect, characters in a field are counted from the beginning of the preceding whitespace. OPTS is one or more single-letter ordering options, which override global ordering options for that key. If no key is given, use the entire line as the key.
Tedy key určuje, které pole (oddělené pomocí whitespace, anebo znaku specifikovaného pomocí -t) se použije pro řazení, číslo za tečkou udává první významný znak, podle kterého se řadí, další písmenka jsou ekvivalentní přepínačům sort-u. Co na tom není jasné?
A kdyz je tam tech 'k' parametru vic, tak co znamena ze se bude radit podle vice klicu?
Tiskni
Sdílej:
ISSN 1214-1267, (c) 1999-2007 Stickfish s.r.o.