开发者

Sorting some find result

开发者 https://www.devze.com 2023-02-25 12:50 出处:网络
I need to sort the output of a find on a HP-UX. I\'ve got the following results : /path/to/folder/one/blabla_110303121212.x

I need to sort the output of a find on a HP-UX. I've got the following results :

/path/to/folder/one/blabla_110303121212.x
/path/to/folder/two/otherblabla_1102124302.x
etc.

With sort -t"\" -k5, I managed to sort from the last /, but now I want to be able to sort from only the last underscore, on the numerical suit. -t can't take two separators (alas), -n didn't work (don't know why), I can't give an exact number to tell with -k second argument where the key starts sin开发者_开发知识库ce the size of "blabla" is never the same, and I need to keep those (admittedly annoying) paths.

Does anyone have any idea ? Thanks in advance !


sort(1) is usually stable which means that it won't disturb the order of elements if they have the same sort key.

So the solution is to sort the output several times; start with the parts after the underscore and then sort for name.

Another solution is to cut the file into columns, change the order of the columns, sort this intermediate file, and then join the columns back into the original form.

With awk(1), you could create

  blabla_                     110303121212.x /path/to/folder/one/
  otherblabla_                  1102124302.x /path/to/folder/two/

This can be sorted without any options; just add enough whitespace between the prefix and the suffix and align the suffix to the right.

0

精彩评论

暂无评论...
验证码 换一张
取 消