Print SHA sums without “-” at the end?
Clash Royale CLAN TAG#URR8PPP
up vote
0
down vote
favorite
Is it possible to have SHA sums print without the -
appended to the end?
$ echo test | sha1sum
4e1243bd22c66e76c2ba9eddc1f91394e57f9f83 - <--- this "-" dash/hyphen
I know we can use awk
and other command line tools, but can it be done without using another tool?
$ echo test | sha1sum | awk 'print $1'
4e1243bd22c66e76c2ba9eddc1f91394e57f9f83
command-line command hashsum checksum sha1sum
add a comment |
up vote
0
down vote
favorite
Is it possible to have SHA sums print without the -
appended to the end?
$ echo test | sha1sum
4e1243bd22c66e76c2ba9eddc1f91394e57f9f83 - <--- this "-" dash/hyphen
I know we can use awk
and other command line tools, but can it be done without using another tool?
$ echo test | sha1sum | awk 'print $1'
4e1243bd22c66e76c2ba9eddc1f91394e57f9f83
command-line command hashsum checksum sha1sum
1
Have you compared the output when you give sha1sum a filename?
– Jeff Schaller
Dec 10 at 1:23
1
Also,man sha1sum
implies (not explicitly) when-
is used.
– Sparhawk
Dec 10 at 1:24
Oh, I see. The-
means the sum was created using stdin? Is it possible to omit the-
using onlysha1sum
?
– user325067
Dec 10 at 1:25
add a comment |
up vote
0
down vote
favorite
up vote
0
down vote
favorite
Is it possible to have SHA sums print without the -
appended to the end?
$ echo test | sha1sum
4e1243bd22c66e76c2ba9eddc1f91394e57f9f83 - <--- this "-" dash/hyphen
I know we can use awk
and other command line tools, but can it be done without using another tool?
$ echo test | sha1sum | awk 'print $1'
4e1243bd22c66e76c2ba9eddc1f91394e57f9f83
command-line command hashsum checksum sha1sum
Is it possible to have SHA sums print without the -
appended to the end?
$ echo test | sha1sum
4e1243bd22c66e76c2ba9eddc1f91394e57f9f83 - <--- this "-" dash/hyphen
I know we can use awk
and other command line tools, but can it be done without using another tool?
$ echo test | sha1sum | awk 'print $1'
4e1243bd22c66e76c2ba9eddc1f91394e57f9f83
command-line command hashsum checksum sha1sum
command-line command hashsum checksum sha1sum
edited Dec 10 at 20:26
Rui F Ribeiro
38.8k1479128
38.8k1479128
asked Dec 10 at 1:08
user325067
32
32
1
Have you compared the output when you give sha1sum a filename?
– Jeff Schaller
Dec 10 at 1:23
1
Also,man sha1sum
implies (not explicitly) when-
is used.
– Sparhawk
Dec 10 at 1:24
Oh, I see. The-
means the sum was created using stdin? Is it possible to omit the-
using onlysha1sum
?
– user325067
Dec 10 at 1:25
add a comment |
1
Have you compared the output when you give sha1sum a filename?
– Jeff Schaller
Dec 10 at 1:23
1
Also,man sha1sum
implies (not explicitly) when-
is used.
– Sparhawk
Dec 10 at 1:24
Oh, I see. The-
means the sum was created using stdin? Is it possible to omit the-
using onlysha1sum
?
– user325067
Dec 10 at 1:25
1
1
Have you compared the output when you give sha1sum a filename?
– Jeff Schaller
Dec 10 at 1:23
Have you compared the output when you give sha1sum a filename?
– Jeff Schaller
Dec 10 at 1:23
1
1
Also,
man sha1sum
implies (not explicitly) when -
is used.– Sparhawk
Dec 10 at 1:24
Also,
man sha1sum
implies (not explicitly) when -
is used.– Sparhawk
Dec 10 at 1:24
Oh, I see. The
-
means the sum was created using stdin? Is it possible to omit the -
using only sha1sum
?– user325067
Dec 10 at 1:25
Oh, I see. The
-
means the sum was created using stdin? Is it possible to omit the -
using only sha1sum
?– user325067
Dec 10 at 1:25
add a comment |
2 Answers
2
active
oldest
votes
up vote
1
down vote
accepted
This is not possible without another tool or without editing the actual sha1sum script/binary. When sha1sum is fed a file it prints the filename after the sum. When sha1sum is not fed a file or is used with a pipe. It puts the - there as a placeholder to indicate that the input was not a file.
1
The-
actually representsstdin
. Fromman md5sum
With no FILE, or when FILE is -, read standard input.
– Isaac
Dec 10 at 8:14
add a comment |
up vote
0
down vote
Newline
Understand that the echo is adding a newline at the end which changes the hash:
$ echo test | sha1sum
4e1243bd22c66e76c2ba9eddc1f91394e57f9f83 -
$ echo -n test | sha1sum
a94a8fe5ccb19ba61c4c0873d391e987982fbbd3 -
Answer
But no, there is no way to make sha1sum to print only the hash. The reason is that the line is actually an encoded string. The line could start with a and the second space (yes, there are two) between the hash and the filename could become a
*
to indicate a binary
hash (useful in DOS):
$ echo "hello" >'afile'
$ md5sum -b 'afile'
b1946ac92492d2347c6235b4d2611184 *a\file
So, no, it is not a good idea to try to parse that output without understanding the above.
Alternatives
A couple of simpler solutions on other languages are:
perl
$ echo "test" | perl -le 'use Digest::SHA qw(sha1_hex); print sha1_hex(<>);'
4e1243bd22c66e76c2ba9eddc1f91394e57f9f83
Or (for longer input, less memory used), write to a file (lets call it sha1.perl
):
use Digest::SHA qw(sha1_hex);
$state = Digest::SHA->new(sha1);
for (<>) $state->add($_)
print $state->hexdigest, "n";
Execute it:
$ echo "test" | perl sha1.perl
4e1243bd22c66e76c2ba9eddc1f91394e57f9f83
php
$ echo "test" | php -r '$f = fgets(STDIN); echo sha1($f),"n";'
4e1243bd22c66e76c2ba9eddc1f91394e57f9f83
python
Write this to a file (lets call it sha1.py
):
import hashlib
m = hashlib.sha1()
import sys
for line in sys.stdin:
m.update(line)
print m.hexdigest()
Use it:
$ echo "test" | python sha1.py
4e1243bd22c66e76c2ba9eddc1f91394e57f9f83
add a comment |
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
);
);
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
Required, but never shown
StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2funix.stackexchange.com%2fquestions%2f487028%2fprint-sha-sums-without-at-the-end%23new-answer', 'question_page');
);
Post as a guest
Required, but never shown
2 Answers
2
active
oldest
votes
2 Answers
2
active
oldest
votes
active
oldest
votes
active
oldest
votes
up vote
1
down vote
accepted
This is not possible without another tool or without editing the actual sha1sum script/binary. When sha1sum is fed a file it prints the filename after the sum. When sha1sum is not fed a file or is used with a pipe. It puts the - there as a placeholder to indicate that the input was not a file.
1
The-
actually representsstdin
. Fromman md5sum
With no FILE, or when FILE is -, read standard input.
– Isaac
Dec 10 at 8:14
add a comment |
up vote
1
down vote
accepted
This is not possible without another tool or without editing the actual sha1sum script/binary. When sha1sum is fed a file it prints the filename after the sum. When sha1sum is not fed a file or is used with a pipe. It puts the - there as a placeholder to indicate that the input was not a file.
1
The-
actually representsstdin
. Fromman md5sum
With no FILE, or when FILE is -, read standard input.
– Isaac
Dec 10 at 8:14
add a comment |
up vote
1
down vote
accepted
up vote
1
down vote
accepted
This is not possible without another tool or without editing the actual sha1sum script/binary. When sha1sum is fed a file it prints the filename after the sum. When sha1sum is not fed a file or is used with a pipe. It puts the - there as a placeholder to indicate that the input was not a file.
This is not possible without another tool or without editing the actual sha1sum script/binary. When sha1sum is fed a file it prints the filename after the sum. When sha1sum is not fed a file or is used with a pipe. It puts the - there as a placeholder to indicate that the input was not a file.
edited Dec 10 at 2:04
answered Dec 10 at 1:47
Michael Prokopec
995116
995116
1
The-
actually representsstdin
. Fromman md5sum
With no FILE, or when FILE is -, read standard input.
– Isaac
Dec 10 at 8:14
add a comment |
1
The-
actually representsstdin
. Fromman md5sum
With no FILE, or when FILE is -, read standard input.
– Isaac
Dec 10 at 8:14
1
1
The
-
actually represents stdin
. From man md5sum
With no FILE, or when FILE is -, read standard input.– Isaac
Dec 10 at 8:14
The
-
actually represents stdin
. From man md5sum
With no FILE, or when FILE is -, read standard input.– Isaac
Dec 10 at 8:14
add a comment |
up vote
0
down vote
Newline
Understand that the echo is adding a newline at the end which changes the hash:
$ echo test | sha1sum
4e1243bd22c66e76c2ba9eddc1f91394e57f9f83 -
$ echo -n test | sha1sum
a94a8fe5ccb19ba61c4c0873d391e987982fbbd3 -
Answer
But no, there is no way to make sha1sum to print only the hash. The reason is that the line is actually an encoded string. The line could start with a and the second space (yes, there are two) between the hash and the filename could become a
*
to indicate a binary
hash (useful in DOS):
$ echo "hello" >'afile'
$ md5sum -b 'afile'
b1946ac92492d2347c6235b4d2611184 *a\file
So, no, it is not a good idea to try to parse that output without understanding the above.
Alternatives
A couple of simpler solutions on other languages are:
perl
$ echo "test" | perl -le 'use Digest::SHA qw(sha1_hex); print sha1_hex(<>);'
4e1243bd22c66e76c2ba9eddc1f91394e57f9f83
Or (for longer input, less memory used), write to a file (lets call it sha1.perl
):
use Digest::SHA qw(sha1_hex);
$state = Digest::SHA->new(sha1);
for (<>) $state->add($_)
print $state->hexdigest, "n";
Execute it:
$ echo "test" | perl sha1.perl
4e1243bd22c66e76c2ba9eddc1f91394e57f9f83
php
$ echo "test" | php -r '$f = fgets(STDIN); echo sha1($f),"n";'
4e1243bd22c66e76c2ba9eddc1f91394e57f9f83
python
Write this to a file (lets call it sha1.py
):
import hashlib
m = hashlib.sha1()
import sys
for line in sys.stdin:
m.update(line)
print m.hexdigest()
Use it:
$ echo "test" | python sha1.py
4e1243bd22c66e76c2ba9eddc1f91394e57f9f83
add a comment |
up vote
0
down vote
Newline
Understand that the echo is adding a newline at the end which changes the hash:
$ echo test | sha1sum
4e1243bd22c66e76c2ba9eddc1f91394e57f9f83 -
$ echo -n test | sha1sum
a94a8fe5ccb19ba61c4c0873d391e987982fbbd3 -
Answer
But no, there is no way to make sha1sum to print only the hash. The reason is that the line is actually an encoded string. The line could start with a and the second space (yes, there are two) between the hash and the filename could become a
*
to indicate a binary
hash (useful in DOS):
$ echo "hello" >'afile'
$ md5sum -b 'afile'
b1946ac92492d2347c6235b4d2611184 *a\file
So, no, it is not a good idea to try to parse that output without understanding the above.
Alternatives
A couple of simpler solutions on other languages are:
perl
$ echo "test" | perl -le 'use Digest::SHA qw(sha1_hex); print sha1_hex(<>);'
4e1243bd22c66e76c2ba9eddc1f91394e57f9f83
Or (for longer input, less memory used), write to a file (lets call it sha1.perl
):
use Digest::SHA qw(sha1_hex);
$state = Digest::SHA->new(sha1);
for (<>) $state->add($_)
print $state->hexdigest, "n";
Execute it:
$ echo "test" | perl sha1.perl
4e1243bd22c66e76c2ba9eddc1f91394e57f9f83
php
$ echo "test" | php -r '$f = fgets(STDIN); echo sha1($f),"n";'
4e1243bd22c66e76c2ba9eddc1f91394e57f9f83
python
Write this to a file (lets call it sha1.py
):
import hashlib
m = hashlib.sha1()
import sys
for line in sys.stdin:
m.update(line)
print m.hexdigest()
Use it:
$ echo "test" | python sha1.py
4e1243bd22c66e76c2ba9eddc1f91394e57f9f83
add a comment |
up vote
0
down vote
up vote
0
down vote
Newline
Understand that the echo is adding a newline at the end which changes the hash:
$ echo test | sha1sum
4e1243bd22c66e76c2ba9eddc1f91394e57f9f83 -
$ echo -n test | sha1sum
a94a8fe5ccb19ba61c4c0873d391e987982fbbd3 -
Answer
But no, there is no way to make sha1sum to print only the hash. The reason is that the line is actually an encoded string. The line could start with a and the second space (yes, there are two) between the hash and the filename could become a
*
to indicate a binary
hash (useful in DOS):
$ echo "hello" >'afile'
$ md5sum -b 'afile'
b1946ac92492d2347c6235b4d2611184 *a\file
So, no, it is not a good idea to try to parse that output without understanding the above.
Alternatives
A couple of simpler solutions on other languages are:
perl
$ echo "test" | perl -le 'use Digest::SHA qw(sha1_hex); print sha1_hex(<>);'
4e1243bd22c66e76c2ba9eddc1f91394e57f9f83
Or (for longer input, less memory used), write to a file (lets call it sha1.perl
):
use Digest::SHA qw(sha1_hex);
$state = Digest::SHA->new(sha1);
for (<>) $state->add($_)
print $state->hexdigest, "n";
Execute it:
$ echo "test" | perl sha1.perl
4e1243bd22c66e76c2ba9eddc1f91394e57f9f83
php
$ echo "test" | php -r '$f = fgets(STDIN); echo sha1($f),"n";'
4e1243bd22c66e76c2ba9eddc1f91394e57f9f83
python
Write this to a file (lets call it sha1.py
):
import hashlib
m = hashlib.sha1()
import sys
for line in sys.stdin:
m.update(line)
print m.hexdigest()
Use it:
$ echo "test" | python sha1.py
4e1243bd22c66e76c2ba9eddc1f91394e57f9f83
Newline
Understand that the echo is adding a newline at the end which changes the hash:
$ echo test | sha1sum
4e1243bd22c66e76c2ba9eddc1f91394e57f9f83 -
$ echo -n test | sha1sum
a94a8fe5ccb19ba61c4c0873d391e987982fbbd3 -
Answer
But no, there is no way to make sha1sum to print only the hash. The reason is that the line is actually an encoded string. The line could start with a and the second space (yes, there are two) between the hash and the filename could become a
*
to indicate a binary
hash (useful in DOS):
$ echo "hello" >'afile'
$ md5sum -b 'afile'
b1946ac92492d2347c6235b4d2611184 *a\file
So, no, it is not a good idea to try to parse that output without understanding the above.
Alternatives
A couple of simpler solutions on other languages are:
perl
$ echo "test" | perl -le 'use Digest::SHA qw(sha1_hex); print sha1_hex(<>);'
4e1243bd22c66e76c2ba9eddc1f91394e57f9f83
Or (for longer input, less memory used), write to a file (lets call it sha1.perl
):
use Digest::SHA qw(sha1_hex);
$state = Digest::SHA->new(sha1);
for (<>) $state->add($_)
print $state->hexdigest, "n";
Execute it:
$ echo "test" | perl sha1.perl
4e1243bd22c66e76c2ba9eddc1f91394e57f9f83
php
$ echo "test" | php -r '$f = fgets(STDIN); echo sha1($f),"n";'
4e1243bd22c66e76c2ba9eddc1f91394e57f9f83
python
Write this to a file (lets call it sha1.py
):
import hashlib
m = hashlib.sha1()
import sys
for line in sys.stdin:
m.update(line)
print m.hexdigest()
Use it:
$ echo "test" | python sha1.py
4e1243bd22c66e76c2ba9eddc1f91394e57f9f83
answered Dec 10 at 11:35
Isaac
11k11648
11k11648
add a comment |
add a comment |
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.
Some of your past answers have not been well-received, and you're in danger of being blocked from answering.
Please pay close attention to the following guidance:
- 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.
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
Required, but never shown
StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2funix.stackexchange.com%2fquestions%2f487028%2fprint-sha-sums-without-at-the-end%23new-answer', 'question_page');
);
Post as a guest
Required, but never shown
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
Required, but never shown
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
Required, but never shown
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
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
1
Have you compared the output when you give sha1sum a filename?
– Jeff Schaller
Dec 10 at 1:23
1
Also,
man sha1sum
implies (not explicitly) when-
is used.– Sparhawk
Dec 10 at 1:24
Oh, I see. The
-
means the sum was created using stdin? Is it possible to omit the-
using onlysha1sum
?– user325067
Dec 10 at 1:25