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

Mobil Contents History Mobil brands Former Mobil brands Lukoil transaction Mobil UK Mobil Australia Mobil New Zealand Mobil Greece Mobil in Japan Mobil in Canada Mobil Egypt See also References External links Navigation menuwww.mobil.com"Mobil Corporation"the original"Our Houston campus""Business & Finance: Socony-Vacuum Corp.""Popular Mechanics""Lubrite Technologies""Exxon Mobil campus 'clearly happening'""Toledo Blade - Google News Archive Search""The Lion and the Moose - How 2 Executives Pulled off the Biggest Merger Ever""ExxonMobil Press Release""Lubricants""Archived copy"the original"Mobil 1™ and Mobil Super™ motor oil and synthetic motor oil - Mobil™ Motor Oils""Mobil Delvac""Mobil Industrial website""The State of Competition in Gasoline Marketing: The Effects of Refiner Operations at Retail""Mobil Travel Guide to become Forbes Travel Guide""Hotel Rankings: Forbes Merges with Mobil"the original"Jamieson oil industry history""Mobil news""Caltex pumps for control""Watchdog blocks Caltex bid""Exxon Mobil sells service station network""Mobil Oil New Zealand Limited is New Zealand's oldest oil company, with predecessor companies having first established a presence in the country in 1896""ExxonMobil subsidiaries have a business history in New Zealand stretching back more than 120 years. We are involved in petroleum refining and distribution and the marketing of fuels, lubricants and chemical products""Archived copy"the original"Exxon Mobil to Sell Its Japanese Arm for $3.9 Billion""Gas station merger will end Esso and Mobil's long run in Japan""Esso moves to affiliate itself with PC Optimum, no longer Aeroplan, in loyalty point switch""Mobil brand of gas stations to launch in Canada after deal for 213 Loblaws-owned locations""Mobil Nears Completion of Rebranding 200 Loblaw Gas Stations""Learn about ExxonMobil's operations in Egypt""Petrol and Diesel Service Stations in Egypt - Mobil"Official websiteExxon Mobil corporate websiteMobil Industrial official websiteeeeeeeeDA04275022275790-40000 0001 0860 5061n82045453134887257134887257

Frič See also Navigation menuinternal link

Identify plant with long narrow paired leaves and reddish stems Planned maintenance scheduled April 17/18, 2019 at 00:00UTC (8:00pm US/Eastern) Announcing the arrival of Valued Associate #679: Cesar Manara Unicorn Meta Zoo #1: Why another podcast?What is this plant with long sharp leaves? Is it a weed?What is this 3ft high, stalky plant, with mid sized narrow leaves?What is this young shrub with opposite ovate, crenate leaves and reddish stems?What is this plant with large broad serrated leaves?Identify this upright branching weed with long leaves and reddish stemsPlease help me identify this bulbous plant with long, broad leaves and white flowersWhat is this small annual with narrow gray/green leaves and rust colored daisy-type flowers?What is this chilli plant?Does anyone know what type of chilli plant this is?Help identify this plant