I have file.txt:


How I can get each string in md5sum using follow command(?):

... | md5sum | sed -r 's/(..){3}/\1:/g;s/\s+-$//'

I trying this:

cat file.txt | md5sum | sed -r 's/(..){3}/\1:/g;s/\s+-$//'

...but this is fail way.

  • Are newline characters terminators that should be dropped? Or should each string contain the trailing newline? – Kamil Maciorowski Jul 30 at 17:47
  • @KamilMaciorowski without newline char. – 0-Level UNIX Monk Jul 30 at 18:38
while IFS= read -r line; do
  printf '%s' "$line" | md5sum
done <file.txt | sed -r 's/(..){3}/\1:/g;s/\s+-$//'

This will read lines from file.txt and send them one by one, each to a separate md5sum. Single sed processes all the output; there's no point in running one sed per line.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.