Multiplying digits inside numbers based on position of digit
Clash Royale CLAN TAG#URR8PPP
up vote
0
down vote
favorite
I have list of numbers like this:
0987656787689
2345453326780
3453212332345
1324532449876
1234532444568
3245321343456
1324354532376
1234532153457
I would like to sort the numbers based on the results of multiplication of digits in positions sixth and seventh, so the results are like this:
3245321343456
3453212332345
1234532153457
1234532444568
1324532449876
2345453326780
1324354532376
0987656787689
sort numeric-data
add a comment |Â
up vote
0
down vote
favorite
I have list of numbers like this:
0987656787689
2345453326780
3453212332345
1324532449876
1234532444568
3245321343456
1324354532376
1234532153457
I would like to sort the numbers based on the results of multiplication of digits in positions sixth and seventh, so the results are like this:
3245321343456
3453212332345
1234532153457
1234532444568
1324532449876
2345453326780
1324354532376
0987656787689
sort numeric-data
add a comment |Â
up vote
0
down vote
favorite
up vote
0
down vote
favorite
I have list of numbers like this:
0987656787689
2345453326780
3453212332345
1324532449876
1234532444568
3245321343456
1324354532376
1234532153457
I would like to sort the numbers based on the results of multiplication of digits in positions sixth and seventh, so the results are like this:
3245321343456
3453212332345
1234532153457
1234532444568
1324532449876
2345453326780
1324354532376
0987656787689
sort numeric-data
I have list of numbers like this:
0987656787689
2345453326780
3453212332345
1324532449876
1234532444568
3245321343456
1324354532376
1234532153457
I would like to sort the numbers based on the results of multiplication of digits in positions sixth and seventh, so the results are like this:
3245321343456
3453212332345
1234532153457
1234532444568
1324532449876
2345453326780
1324354532376
0987656787689
sort numeric-data
sort numeric-data
edited 10 mins ago
Jeff Schaller
33.9k851113
33.9k851113
asked 37 mins ago
Koran
345
345
add a comment |Â
add a comment |Â
2 Answers
2
active
oldest
votes
up vote
1
down vote
accepted
Using awk
:
$ awk ' print substr($0,6,1)*substr($0,7,1) ' <file
30
15
2
6
6
2
20
6
Sorting the original numbers based on the the above result (this was a followup question in a comment):
$ awk ' print substr($0,6,1)*substr($0,7,1) ' <file | paste - file | sort -n | cut -f 2
3245321343456
3453212332345
1234532153457
1234532444568
1324532449876
2345453326780
1324354532376
0987656787689
This pastes the result of the multiplication together with the original numbers as two separate tab-delimited columns, then sorts it numerically and extracts the second column (the original numbers).
thank you very much this is stunning I spent three days on this ;(
â Koran
22 mins ago
1
@Koran Yes, asking followup questions is generally frowned upon. The question should be complete from the start. If you keep adding to it or changing it, you will invalidate given answers, and people will just be confused when trying to follow what's going on.
â Kusalananda
16 mins ago
1
@Goro I did update the question. sorry about confusion thank you
â Koran
16 mins ago
add a comment |Â
up vote
1
down vote
Perl to the rescue!
perl -F// -lane 'print $F[5] * $F[6]' < file
-n
reads the input line by line-a
splits each line into the @F array-F
tells how to split//
means to split everywhere, i.e. into single characters-l
removes newlines from input and adds them to output
thank you very much for the quick response! Appreciated! I have one last question please, how can I sort the numbers based on the multiplication of the digits in positions 6 and 7?
â Koran
31 mins ago
add a comment |Â
2 Answers
2
active
oldest
votes
2 Answers
2
active
oldest
votes
active
oldest
votes
active
oldest
votes
up vote
1
down vote
accepted
Using awk
:
$ awk ' print substr($0,6,1)*substr($0,7,1) ' <file
30
15
2
6
6
2
20
6
Sorting the original numbers based on the the above result (this was a followup question in a comment):
$ awk ' print substr($0,6,1)*substr($0,7,1) ' <file | paste - file | sort -n | cut -f 2
3245321343456
3453212332345
1234532153457
1234532444568
1324532449876
2345453326780
1324354532376
0987656787689
This pastes the result of the multiplication together with the original numbers as two separate tab-delimited columns, then sorts it numerically and extracts the second column (the original numbers).
thank you very much this is stunning I spent three days on this ;(
â Koran
22 mins ago
1
@Koran Yes, asking followup questions is generally frowned upon. The question should be complete from the start. If you keep adding to it or changing it, you will invalidate given answers, and people will just be confused when trying to follow what's going on.
â Kusalananda
16 mins ago
1
@Goro I did update the question. sorry about confusion thank you
â Koran
16 mins ago
add a comment |Â
up vote
1
down vote
accepted
Using awk
:
$ awk ' print substr($0,6,1)*substr($0,7,1) ' <file
30
15
2
6
6
2
20
6
Sorting the original numbers based on the the above result (this was a followup question in a comment):
$ awk ' print substr($0,6,1)*substr($0,7,1) ' <file | paste - file | sort -n | cut -f 2
3245321343456
3453212332345
1234532153457
1234532444568
1324532449876
2345453326780
1324354532376
0987656787689
This pastes the result of the multiplication together with the original numbers as two separate tab-delimited columns, then sorts it numerically and extracts the second column (the original numbers).
thank you very much this is stunning I spent three days on this ;(
â Koran
22 mins ago
1
@Koran Yes, asking followup questions is generally frowned upon. The question should be complete from the start. If you keep adding to it or changing it, you will invalidate given answers, and people will just be confused when trying to follow what's going on.
â Kusalananda
16 mins ago
1
@Goro I did update the question. sorry about confusion thank you
â Koran
16 mins ago
add a comment |Â
up vote
1
down vote
accepted
up vote
1
down vote
accepted
Using awk
:
$ awk ' print substr($0,6,1)*substr($0,7,1) ' <file
30
15
2
6
6
2
20
6
Sorting the original numbers based on the the above result (this was a followup question in a comment):
$ awk ' print substr($0,6,1)*substr($0,7,1) ' <file | paste - file | sort -n | cut -f 2
3245321343456
3453212332345
1234532153457
1234532444568
1324532449876
2345453326780
1324354532376
0987656787689
This pastes the result of the multiplication together with the original numbers as two separate tab-delimited columns, then sorts it numerically and extracts the second column (the original numbers).
Using awk
:
$ awk ' print substr($0,6,1)*substr($0,7,1) ' <file
30
15
2
6
6
2
20
6
Sorting the original numbers based on the the above result (this was a followup question in a comment):
$ awk ' print substr($0,6,1)*substr($0,7,1) ' <file | paste - file | sort -n | cut -f 2
3245321343456
3453212332345
1234532153457
1234532444568
1324532449876
2345453326780
1324354532376
0987656787689
This pastes the result of the multiplication together with the original numbers as two separate tab-delimited columns, then sorts it numerically and extracts the second column (the original numbers).
edited 22 mins ago
answered 26 mins ago
Kusalananda
109k14213336
109k14213336
thank you very much this is stunning I spent three days on this ;(
â Koran
22 mins ago
1
@Koran Yes, asking followup questions is generally frowned upon. The question should be complete from the start. If you keep adding to it or changing it, you will invalidate given answers, and people will just be confused when trying to follow what's going on.
â Kusalananda
16 mins ago
1
@Goro I did update the question. sorry about confusion thank you
â Koran
16 mins ago
add a comment |Â
thank you very much this is stunning I spent three days on this ;(
â Koran
22 mins ago
1
@Koran Yes, asking followup questions is generally frowned upon. The question should be complete from the start. If you keep adding to it or changing it, you will invalidate given answers, and people will just be confused when trying to follow what's going on.
â Kusalananda
16 mins ago
1
@Goro I did update the question. sorry about confusion thank you
â Koran
16 mins ago
thank you very much this is stunning I spent three days on this ;(
â Koran
22 mins ago
thank you very much this is stunning I spent three days on this ;(
â Koran
22 mins ago
1
1
@Koran Yes, asking followup questions is generally frowned upon. The question should be complete from the start. If you keep adding to it or changing it, you will invalidate given answers, and people will just be confused when trying to follow what's going on.
â Kusalananda
16 mins ago
@Koran Yes, asking followup questions is generally frowned upon. The question should be complete from the start. If you keep adding to it or changing it, you will invalidate given answers, and people will just be confused when trying to follow what's going on.
â Kusalananda
16 mins ago
1
1
@Goro I did update the question. sorry about confusion thank you
â Koran
16 mins ago
@Goro I did update the question. sorry about confusion thank you
â Koran
16 mins ago
add a comment |Â
up vote
1
down vote
Perl to the rescue!
perl -F// -lane 'print $F[5] * $F[6]' < file
-n
reads the input line by line-a
splits each line into the @F array-F
tells how to split//
means to split everywhere, i.e. into single characters-l
removes newlines from input and adds them to output
thank you very much for the quick response! Appreciated! I have one last question please, how can I sort the numbers based on the multiplication of the digits in positions 6 and 7?
â Koran
31 mins ago
add a comment |Â
up vote
1
down vote
Perl to the rescue!
perl -F// -lane 'print $F[5] * $F[6]' < file
-n
reads the input line by line-a
splits each line into the @F array-F
tells how to split//
means to split everywhere, i.e. into single characters-l
removes newlines from input and adds them to output
thank you very much for the quick response! Appreciated! I have one last question please, how can I sort the numbers based on the multiplication of the digits in positions 6 and 7?
â Koran
31 mins ago
add a comment |Â
up vote
1
down vote
up vote
1
down vote
Perl to the rescue!
perl -F// -lane 'print $F[5] * $F[6]' < file
-n
reads the input line by line-a
splits each line into the @F array-F
tells how to split//
means to split everywhere, i.e. into single characters-l
removes newlines from input and adds them to output
Perl to the rescue!
perl -F// -lane 'print $F[5] * $F[6]' < file
-n
reads the input line by line-a
splits each line into the @F array-F
tells how to split//
means to split everywhere, i.e. into single characters-l
removes newlines from input and adds them to output
answered 33 mins ago
choroba
25.1k34269
25.1k34269
thank you very much for the quick response! Appreciated! I have one last question please, how can I sort the numbers based on the multiplication of the digits in positions 6 and 7?
â Koran
31 mins ago
add a comment |Â
thank you very much for the quick response! Appreciated! I have one last question please, how can I sort the numbers based on the multiplication of the digits in positions 6 and 7?
â Koran
31 mins ago
thank you very much for the quick response! Appreciated! I have one last question please, how can I sort the numbers based on the multiplication of the digits in positions 6 and 7?
â Koran
31 mins ago
thank you very much for the quick response! Appreciated! I have one last question please, how can I sort the numbers based on the multiplication of the digits in positions 6 and 7?
â Koran
31 mins ago
add a comment |Â
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2funix.stackexchange.com%2fquestions%2f475321%2fmultiplying-digits-inside-numbers-based-on-position-of-digit%23new-answer', 'question_page');
);
Post as a guest
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password