Попытка отсортировать определенные столбцы в linux

deman xargs:

--delimiter=delim
-d delim

Input items are terminated by the specified character. Quotes and backslash are not special every character in the input is taken literally. Disables the end-of-file string, which is treated like any other argument. This can be used when the input consists of simply newline-separated items, although it is almost always better to design your program to use --null where this is possible. The specified delimiter may be a single character, a C-style character escape such as \n, or an octal or hexadecimal escape code. Octal and hexadecimal escape codes are understood as for the printf command. Multibyte characters are not supported.

Tome nota de los comentarios a la pregunta y tómelos en serio. Esta respuesta se puede encontrar fácilmente consultando su propia página man, o usando su motor de búsqueda favorito para buscar una versión en línea -de la página man, o buscando man xargs -d.

1
17.02.2019, 22:22
2 ответа

Ваш пример содержит уникальные значения поля 1 (идентификационный номер ), поэтому, если данные отсортированы по идентификатору, последующая сортировка по имени не будет иметь никакого эффекта.

Программа sort сортирует весь файл, не ища строк заголовка...

Следующая программа Awk печатает строку заголовка и отправляет все последующие строки на сортировку.

awk '{if (NR==1) {print $0} {print $0 | "sort -k1,1 -k2,2"}}' <filename>
3
28.04.2021, 23:36

С гну сед и сорт:

sed -z 'h;s/\n.*//;x;s/[^\n]*\n//;s/.*/echo "&"|sort -k1,1 -k2,2/e;x;G' infile
0
28.04.2021, 23:36

Теги

Похожие вопросы