0

I've got the following bash code:

md5sum -c checksum.md5 2>&1 | grep FAILED | awk '{print $1}' | sed 's/:$// > /tmp/check.tmp
awk '{system("wget http://example.com/"$1"")}' /tmp/check.tmp

How can I use awk without a temp file?

Something like

files=`md5sum -c checksum.md5 2>&1 | grep FAILED | awk '{print $1}' | sed 's/:$//`
awk '{system("wget http://example.com/"$1"")}' $files
2
  • Post input and output, it can almost deinfintely all be done in awk. Commented Jul 1, 2015 at 8:05
  • Piping sed to awk does not work? However, the tasks done by grep and sed here could be most likely done by awk too. Commented Jul 1, 2015 at 8:06

3 Answers 3

2

You can simplify the whole command to this:

md5sum -c checksum.md5 2>&1 |\
    awk -F'[:/]' '/FAILED/{system("wget http://example.com/"$(NF-1))}'
Sign up to request clarification or add additional context in comments.

3 Comments

Thank you! That's great, but a bit difficult
You are missing closing quotes.
@User112638726 Thanks, added them. The solution would also work only as long as file names doesn't contain :,;,$,(),{}, spaces, tabs or newlines. I'm not really happpy with it already, but you see, it's already too difficult. ;)
2

wget has a switch -i that can come in handy:

md5sum -c checksum.md5 2>&1 | \
    sed -n '/FAILED$/ { s/: FAILED$//; s!^!http://example.com/!; p; }' | \
    wget -i

Comments

1

Like this:

awk '{system("wget http://example.com/"$1"")}' <<< $files

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.