1

I have file.txt:

string1
string2
string3
string4

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.

2
  • Are newline characters terminators that should be dropped? Or should each string contain the trailing newline? Jul 30, 2019 at 17:47
  • @KamilMaciorowski without newline char. Jul 30, 2019 at 18:38

1 Answer 1

3
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.

1
  • Thanks for answer. It works! Jul 30, 2019 at 19:04

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .