sort command understanding the logical sequenceHelp with the sort command (numeric)openSuSE power management from command linePrint random lines respecting the order of the source fileUnderstanding options to sortsort (difference between default and numerical option -n)How to protect potentially destructive command line options?How to add a public key into system keyring for kernel without recompile?sort with -k greater than number of keysHow to automatically scroll to requested command when the “General Commands Manual” is shown?Terminal sort command options: sort -k1,1

Too soon for a plot twist?

Is divide-by-zero a security vulnerability?

How exactly does an Ethernet collision happen in the cable, since nodes use different circuits for Tx and Rx?

Is it a Cyclops number? "Nobody" knows!

The (Easy) Road to Code

How do we create new idioms and use them in a novel?

What will happen if my luggage gets delayed?

Is there stress on two letters on the word стоят

Why does this boat have a landing pad? (SpaceX's GO Searcher) Any plans for propulsive capsule landings?

Do Paladin Auras of Differing Oaths Stack?

Why do phishing e-mails use faked e-mail addresses instead of the real one?

Why is there an extra space when I type "ls" on the Desktop?

Professor forcing me to attend a conference, I can't afford even with 50% funding

Does the US political system, in principle, allow for a no-party system?

What does *dead* mean in *What do you mean, dead?*?

How to install round brake pads

Leveling the sagging side of the home

Which country has more?

What is Tony Stark injecting into himself in Iron Man 3?

Translation of 答えを知っている人はいませんでした

Origin of the word “pushka”

What would be the most expensive material to an intergalactic society?

Is there a math expression equivalent to the conditional ternary operator?

Movie: boy escapes the real world and goes to a fantasy world with big furry trolls



sort command understanding the logical sequence


Help with the sort command (numeric)openSuSE power management from command linePrint random lines respecting the order of the source fileUnderstanding options to sortsort (difference between default and numerical option -n)How to protect potentially destructive command line options?How to add a public key into system keyring for kernel without recompile?sort with -k greater than number of keysHow to automatically scroll to requested command when the “General Commands Manual” is shown?Terminal sort command options: sort -k1,1













1















sort -k 2 filename.txt means that it sorts by the second key but what would this following command mean: sort -k 3.3,3.5 for this data:
For example: I got this-->



Man in Winter England 1980.12.02 
Richrd Fritz Scottland 1960.12.18
Max Winter GB 1955.12.09
Luther Arnold England 1990.05.12
Sebastian Kalle USA 1980.12.14


How can I get the solution for that list with this command:
sort -k 3.3,3.5 data.txt?



And how can you sort it by when you have 2 decimal numbers in general?










share|improve this question



















  • 2





    sort -k3.3,3.5 is explained in the manual... the rest of your post doesn't make much sense...

    – don_crissti
    Feb 14 '17 at 20:07







  • 1





    Does your input contain tabs or spaces? Is the character between "Man" and "in" a space?

    – choroba
    Feb 14 '17 at 20:36















1















sort -k 2 filename.txt means that it sorts by the second key but what would this following command mean: sort -k 3.3,3.5 for this data:
For example: I got this-->



Man in Winter England 1980.12.02 
Richrd Fritz Scottland 1960.12.18
Max Winter GB 1955.12.09
Luther Arnold England 1990.05.12
Sebastian Kalle USA 1980.12.14


How can I get the solution for that list with this command:
sort -k 3.3,3.5 data.txt?



And how can you sort it by when you have 2 decimal numbers in general?










share|improve this question



















  • 2





    sort -k3.3,3.5 is explained in the manual... the rest of your post doesn't make much sense...

    – don_crissti
    Feb 14 '17 at 20:07







  • 1





    Does your input contain tabs or spaces? Is the character between "Man" and "in" a space?

    – choroba
    Feb 14 '17 at 20:36













1












1








1








sort -k 2 filename.txt means that it sorts by the second key but what would this following command mean: sort -k 3.3,3.5 for this data:
For example: I got this-->



Man in Winter England 1980.12.02 
Richrd Fritz Scottland 1960.12.18
Max Winter GB 1955.12.09
Luther Arnold England 1990.05.12
Sebastian Kalle USA 1980.12.14


How can I get the solution for that list with this command:
sort -k 3.3,3.5 data.txt?



And how can you sort it by when you have 2 decimal numbers in general?










share|improve this question
















sort -k 2 filename.txt means that it sorts by the second key but what would this following command mean: sort -k 3.3,3.5 for this data:
For example: I got this-->



Man in Winter England 1980.12.02 
Richrd Fritz Scottland 1960.12.18
Max Winter GB 1955.12.09
Luther Arnold England 1990.05.12
Sebastian Kalle USA 1980.12.14


How can I get the solution for that list with this command:
sort -k 3.3,3.5 data.txt?



And how can you sort it by when you have 2 decimal numbers in general?







linux command-line terminal opensuse sort






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited 53 mins ago









Rui F Ribeiro

41.3k1481140




41.3k1481140










asked Feb 14 '17 at 20:05









AbdiAbdi

102




102







  • 2





    sort -k3.3,3.5 is explained in the manual... the rest of your post doesn't make much sense...

    – don_crissti
    Feb 14 '17 at 20:07







  • 1





    Does your input contain tabs or spaces? Is the character between "Man" and "in" a space?

    – choroba
    Feb 14 '17 at 20:36












  • 2





    sort -k3.3,3.5 is explained in the manual... the rest of your post doesn't make much sense...

    – don_crissti
    Feb 14 '17 at 20:07







  • 1





    Does your input contain tabs or spaces? Is the character between "Man" and "in" a space?

    – choroba
    Feb 14 '17 at 20:36







2




2





sort -k3.3,3.5 is explained in the manual... the rest of your post doesn't make much sense...

– don_crissti
Feb 14 '17 at 20:07






sort -k3.3,3.5 is explained in the manual... the rest of your post doesn't make much sense...

– don_crissti
Feb 14 '17 at 20:07





1




1





Does your input contain tabs or spaces? Is the character between "Man" and "in" a space?

– choroba
Feb 14 '17 at 20:36





Does your input contain tabs or spaces? Is the character between "Man" and "in" a space?

– choroba
Feb 14 '17 at 20:36










1 Answer
1






active

oldest

votes


















1














Let's assume there are no tabs in the input. The interpretation of the command is pretty tricky:



sort -k3.3,3.5


means "sort by a substring from the third field from the third to the fifth character", but the counting begins at the first whitespace before the field, as mentioned in man sort:




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. If neither -t nor -b is in effect,
characters in a field are counted from the beginning of the preceding whitespace.




Run the sort under LC_ALL=C to avoid locale influencing he sort order.



Note how the order changes if you add one more character, i.e.



LC_ALL=C sort -k3.3,3.6


Here's a short Perl script that shows what part of the input is used for sorting:



#!/usr/bin/perl
use warnings;
use strict;
use feature qw say ;

my $field_index = 3;
my $start = 3;
my $stop = 5; # Change to 6 to explain the different order.

while (my $line = <>)
chomp $line;
my @fields = $line =~ /(s*S*)/g;

my $length_before = 0;
$length_before += length $fields[$_] for 0 .. $field_index - 2;

my $from = $start - 1 + $length_before;
my $to = $stop + $length_before;
$_ > length $line and $_ = length $line for $from, $to;

substr $line, $to, 0, '>>';
substr $line, $from, 0, '<<';

say $line;



Output for 3.3,3.5:



Luther Arnold << >>England 1990.05.12
Man in << >>Winter England 1980.12.02
Max Winter << >>GB 1955.12.09
Richrd Fritz << >> Scottland 1960.12.18
Sebastian Kalle << >> USA 1980.12.14


Output for 3.3,3.6:



Richrd Fritz << >>Scottland 1960.12.18
Sebastian Kalle << >>USA 1980.12.14
Luther Arnold << E>>ngland 1990.05.12
Max Winter << G>>B 1955.12.09
Man in << W>>inter England 1980.12.02





share|improve this answer

























  • something I've found useful (since the Q is tagged Linux, they probably have GNU sort) is the sort --debug option. Takes a little getting used to, but it shows what fields are being used for the sort as it goes along.

    – Jeff Schaller
    Feb 15 '17 at 12:08











  • @JeffSchaller: Oh yes, that's what I wasted time simultating!

    – choroba
    Feb 15 '17 at 12:20










Your Answer








StackExchange.ready(function()
var channelOptions =
tags: "".split(" "),
id: "106"
;
initTagRenderer("".split(" "), "".split(" "), channelOptions);

StackExchange.using("externalEditor", function()
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled)
StackExchange.using("snippets", function()
createEditor();
);

else
createEditor();

);

function createEditor()
StackExchange.prepareEditor(
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: false,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: null,
bindNavPrevention: true,
postfix: "",
imageUploader:
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
,
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
);



);













draft saved

draft discarded


















StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2funix.stackexchange.com%2fquestions%2f345013%2fsort-command-understanding-the-logical-sequence%23new-answer', 'question_page');

);

Post as a guest















Required, but never shown

























1 Answer
1






active

oldest

votes








1 Answer
1






active

oldest

votes









active

oldest

votes






active

oldest

votes









1














Let's assume there are no tabs in the input. The interpretation of the command is pretty tricky:



sort -k3.3,3.5


means "sort by a substring from the third field from the third to the fifth character", but the counting begins at the first whitespace before the field, as mentioned in man sort:




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. If neither -t nor -b is in effect,
characters in a field are counted from the beginning of the preceding whitespace.




Run the sort under LC_ALL=C to avoid locale influencing he sort order.



Note how the order changes if you add one more character, i.e.



LC_ALL=C sort -k3.3,3.6


Here's a short Perl script that shows what part of the input is used for sorting:



#!/usr/bin/perl
use warnings;
use strict;
use feature qw say ;

my $field_index = 3;
my $start = 3;
my $stop = 5; # Change to 6 to explain the different order.

while (my $line = <>)
chomp $line;
my @fields = $line =~ /(s*S*)/g;

my $length_before = 0;
$length_before += length $fields[$_] for 0 .. $field_index - 2;

my $from = $start - 1 + $length_before;
my $to = $stop + $length_before;
$_ > length $line and $_ = length $line for $from, $to;

substr $line, $to, 0, '>>';
substr $line, $from, 0, '<<';

say $line;



Output for 3.3,3.5:



Luther Arnold << >>England 1990.05.12
Man in << >>Winter England 1980.12.02
Max Winter << >>GB 1955.12.09
Richrd Fritz << >> Scottland 1960.12.18
Sebastian Kalle << >> USA 1980.12.14


Output for 3.3,3.6:



Richrd Fritz << >>Scottland 1960.12.18
Sebastian Kalle << >>USA 1980.12.14
Luther Arnold << E>>ngland 1990.05.12
Max Winter << G>>B 1955.12.09
Man in << W>>inter England 1980.12.02





share|improve this answer

























  • something I've found useful (since the Q is tagged Linux, they probably have GNU sort) is the sort --debug option. Takes a little getting used to, but it shows what fields are being used for the sort as it goes along.

    – Jeff Schaller
    Feb 15 '17 at 12:08











  • @JeffSchaller: Oh yes, that's what I wasted time simultating!

    – choroba
    Feb 15 '17 at 12:20















1














Let's assume there are no tabs in the input. The interpretation of the command is pretty tricky:



sort -k3.3,3.5


means "sort by a substring from the third field from the third to the fifth character", but the counting begins at the first whitespace before the field, as mentioned in man sort:




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. If neither -t nor -b is in effect,
characters in a field are counted from the beginning of the preceding whitespace.




Run the sort under LC_ALL=C to avoid locale influencing he sort order.



Note how the order changes if you add one more character, i.e.



LC_ALL=C sort -k3.3,3.6


Here's a short Perl script that shows what part of the input is used for sorting:



#!/usr/bin/perl
use warnings;
use strict;
use feature qw say ;

my $field_index = 3;
my $start = 3;
my $stop = 5; # Change to 6 to explain the different order.

while (my $line = <>)
chomp $line;
my @fields = $line =~ /(s*S*)/g;

my $length_before = 0;
$length_before += length $fields[$_] for 0 .. $field_index - 2;

my $from = $start - 1 + $length_before;
my $to = $stop + $length_before;
$_ > length $line and $_ = length $line for $from, $to;

substr $line, $to, 0, '>>';
substr $line, $from, 0, '<<';

say $line;



Output for 3.3,3.5:



Luther Arnold << >>England 1990.05.12
Man in << >>Winter England 1980.12.02
Max Winter << >>GB 1955.12.09
Richrd Fritz << >> Scottland 1960.12.18
Sebastian Kalle << >> USA 1980.12.14


Output for 3.3,3.6:



Richrd Fritz << >>Scottland 1960.12.18
Sebastian Kalle << >>USA 1980.12.14
Luther Arnold << E>>ngland 1990.05.12
Max Winter << G>>B 1955.12.09
Man in << W>>inter England 1980.12.02





share|improve this answer

























  • something I've found useful (since the Q is tagged Linux, they probably have GNU sort) is the sort --debug option. Takes a little getting used to, but it shows what fields are being used for the sort as it goes along.

    – Jeff Schaller
    Feb 15 '17 at 12:08











  • @JeffSchaller: Oh yes, that's what I wasted time simultating!

    – choroba
    Feb 15 '17 at 12:20













1












1








1







Let's assume there are no tabs in the input. The interpretation of the command is pretty tricky:



sort -k3.3,3.5


means "sort by a substring from the third field from the third to the fifth character", but the counting begins at the first whitespace before the field, as mentioned in man sort:




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. If neither -t nor -b is in effect,
characters in a field are counted from the beginning of the preceding whitespace.




Run the sort under LC_ALL=C to avoid locale influencing he sort order.



Note how the order changes if you add one more character, i.e.



LC_ALL=C sort -k3.3,3.6


Here's a short Perl script that shows what part of the input is used for sorting:



#!/usr/bin/perl
use warnings;
use strict;
use feature qw say ;

my $field_index = 3;
my $start = 3;
my $stop = 5; # Change to 6 to explain the different order.

while (my $line = <>)
chomp $line;
my @fields = $line =~ /(s*S*)/g;

my $length_before = 0;
$length_before += length $fields[$_] for 0 .. $field_index - 2;

my $from = $start - 1 + $length_before;
my $to = $stop + $length_before;
$_ > length $line and $_ = length $line for $from, $to;

substr $line, $to, 0, '>>';
substr $line, $from, 0, '<<';

say $line;



Output for 3.3,3.5:



Luther Arnold << >>England 1990.05.12
Man in << >>Winter England 1980.12.02
Max Winter << >>GB 1955.12.09
Richrd Fritz << >> Scottland 1960.12.18
Sebastian Kalle << >> USA 1980.12.14


Output for 3.3,3.6:



Richrd Fritz << >>Scottland 1960.12.18
Sebastian Kalle << >>USA 1980.12.14
Luther Arnold << E>>ngland 1990.05.12
Max Winter << G>>B 1955.12.09
Man in << W>>inter England 1980.12.02





share|improve this answer















Let's assume there are no tabs in the input. The interpretation of the command is pretty tricky:



sort -k3.3,3.5


means "sort by a substring from the third field from the third to the fifth character", but the counting begins at the first whitespace before the field, as mentioned in man sort:




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. If neither -t nor -b is in effect,
characters in a field are counted from the beginning of the preceding whitespace.




Run the sort under LC_ALL=C to avoid locale influencing he sort order.



Note how the order changes if you add one more character, i.e.



LC_ALL=C sort -k3.3,3.6


Here's a short Perl script that shows what part of the input is used for sorting:



#!/usr/bin/perl
use warnings;
use strict;
use feature qw say ;

my $field_index = 3;
my $start = 3;
my $stop = 5; # Change to 6 to explain the different order.

while (my $line = <>)
chomp $line;
my @fields = $line =~ /(s*S*)/g;

my $length_before = 0;
$length_before += length $fields[$_] for 0 .. $field_index - 2;

my $from = $start - 1 + $length_before;
my $to = $stop + $length_before;
$_ > length $line and $_ = length $line for $from, $to;

substr $line, $to, 0, '>>';
substr $line, $from, 0, '<<';

say $line;



Output for 3.3,3.5:



Luther Arnold << >>England 1990.05.12
Man in << >>Winter England 1980.12.02
Max Winter << >>GB 1955.12.09
Richrd Fritz << >> Scottland 1960.12.18
Sebastian Kalle << >> USA 1980.12.14


Output for 3.3,3.6:



Richrd Fritz << >>Scottland 1960.12.18
Sebastian Kalle << >>USA 1980.12.14
Luther Arnold << E>>ngland 1990.05.12
Max Winter << G>>B 1955.12.09
Man in << W>>inter England 1980.12.02






share|improve this answer














share|improve this answer



share|improve this answer








edited Feb 14 '17 at 21:09

























answered Feb 14 '17 at 20:52









chorobachoroba

26.8k45075




26.8k45075












  • something I've found useful (since the Q is tagged Linux, they probably have GNU sort) is the sort --debug option. Takes a little getting used to, but it shows what fields are being used for the sort as it goes along.

    – Jeff Schaller
    Feb 15 '17 at 12:08











  • @JeffSchaller: Oh yes, that's what I wasted time simultating!

    – choroba
    Feb 15 '17 at 12:20

















  • something I've found useful (since the Q is tagged Linux, they probably have GNU sort) is the sort --debug option. Takes a little getting used to, but it shows what fields are being used for the sort as it goes along.

    – Jeff Schaller
    Feb 15 '17 at 12:08











  • @JeffSchaller: Oh yes, that's what I wasted time simultating!

    – choroba
    Feb 15 '17 at 12:20
















something I've found useful (since the Q is tagged Linux, they probably have GNU sort) is the sort --debug option. Takes a little getting used to, but it shows what fields are being used for the sort as it goes along.

– Jeff Schaller
Feb 15 '17 at 12:08





something I've found useful (since the Q is tagged Linux, they probably have GNU sort) is the sort --debug option. Takes a little getting used to, but it shows what fields are being used for the sort as it goes along.

– Jeff Schaller
Feb 15 '17 at 12:08













@JeffSchaller: Oh yes, that's what I wasted time simultating!

– choroba
Feb 15 '17 at 12:20





@JeffSchaller: Oh yes, that's what I wasted time simultating!

– choroba
Feb 15 '17 at 12:20

















draft saved

draft discarded
















































Thanks for contributing an answer to Unix & Linux Stack Exchange!


  • Please be sure to answer the question. Provide details and share your research!

But avoid


  • Asking for help, clarification, or responding to other answers.

  • Making statements based on opinion; back them up with references or personal experience.

To learn more, see our tips on writing great answers.




draft saved


draft discarded














StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2funix.stackexchange.com%2fquestions%2f345013%2fsort-command-understanding-the-logical-sequence%23new-answer', 'question_page');

);

Post as a guest















Required, but never shown





















































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown

































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown







Popular posts from this blog

Creating 100m^2 grid automatically using QGIS?Creating grid constrained within polygon in QGIS?Createing polygon layer from point data using QGIS?Creating vector grid using QGIS?Creating grid polygons from coordinates using R or PythonCreating grid from spatio temporal point data?Creating fields in attributes table using other layers using QGISCreate .shp vector grid in QGISQGIS Creating 4km point grid within polygonsCreate a vector grid over a raster layerVector Grid Creates just one grid

Nikolai Prilezhaev Bibliography References External links Navigation menuEarly Russian Organic Chemists and Their Legacy092774english translationRussian Biography

How to link a C library to an Assembly library on Mac with clangHow do you set, clear, and toggle a single bit?Find (and kill) process locking port 3000 on MacWho is listening on a given TCP port on Mac OS X?How to start PostgreSQL server on Mac OS X?Compile assembler in nasm on mac osHow do I install pip on macOS or OS X?AFNetworking 2.0 “_NSURLSessionTransferSizeUnknown” linking error on Mac OS X 10.8C++ code for testing the Collatz conjecture faster than hand-written assembly - why?How to link a NASM code and GCC in Mac OS X?How to run x86 .asm on macOS Sierra