Groups | Search | Server Info | Keyboard shortcuts | Login | Register
Groups > gnu.emacs.help > #60699
| From | Cecil Westerhof <Cecil@decebal.nl> |
|---|---|
| Newsgroups | gnu.emacs.help |
| Subject | Re: Sort from second field instead on second field |
| Date | 2023-03-30 07:03 +0200 |
| Organization | Decebal Computing |
| Message-ID | <87355mltko.fsf@munus.decebal.nl> (permalink) |
| References | <87sfdnlfkj.fsf@munus.decebal.nl> <yga4jq3v55a.fsf@akutech.de> |
Ralf Fassel <ralfixx@gmx.de> writes:
> * Cecil Westerhof <Cecil@decebal.nl>
> | You can sort lines in the region on the second field with:
> | C-u 2 M-x sort-field
>>
> | In most cases this will probably be enough. But what if I would want
> | to sort from the second field to the end of the line?
>
> Mark the region and call
>
> C-u M-x shell-command-on-region RET sort -k FIELDNUM RET
>
> -k, --key=KEYDEF
> sort via a key; KEYDEF gives location and type
>
> KEYDEF is F[.C][OPTS][,F[.C][OPTS]] for start and stop position, where
> F is a field number and C a character position in the field; both are
> origin 1, and the stop position defaults to the line's end. [...]
>
> ? Of course requires an external command compatible with Unix' 'sort(1)'.
For me that would work because I am on Debian. I was thinking about
this originally, but then I saw that Emacs had his own internal
commands. So I thought that is better. It can be done in the way HASM
said. (And it is really neat.) But I think that this is a better, or
at least easier way. So next time I will use the external sort
command.
Thanks.
I have:
📱 Mobile Phone
😭 Loudly Crying Face
🪟 Window
🏡 House with Garden
💔 Broken Heart
🏠 House
🥳 Partying Face
🥵 Hot Face
And when using (I prefer long options):
C-u M-x shell-command-on-region RET sort --key=2 RET
I get:
💔 Broken Heart
🥵 Hot Face
🏠 House
🏡 House with Garden
😭 Loudly Crying Face
📱 Mobile Phone
🥳 Partying Face
🪟 Window
--
Cecil Westerhof
Senior Software Engineer
LinkedIn: http://www.linkedin.com/in/cecilwesterhof
Back to gnu.emacs.help | Previous | Next — Previous in thread | Find similar
Sort from second field instead on second field Cecil Westerhof <Cecil@decebal.nl> - 2023-03-29 17:53 +0200
Re: Sort from second field instead on second field HASM <hasm@example.invalid> - 2023-03-29 09:39 -0700
Re: Sort from second field instead on second field Cecil Westerhof <Cecil@decebal.nl> - 2023-03-29 19:55 +0200
Re: Sort from second field instead on second field Ralf Fassel <ralfixx@gmx.de> - 2023-03-29 19:28 +0200
Re: Sort from second field instead on second field Cecil Westerhof <Cecil@decebal.nl> - 2023-03-30 07:03 +0200
csiph-web