chs_voks
chs_voks

Reputation: 35

AWK variable input

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

Upvotes: 0

Views: 220

Answers (3)

lcd047
lcd047

Reputation: 5861

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

Upvotes: 2

hek2mgl
hek2mgl

Reputation: 158110

You can simplify the whole command to this:

md5sum -c checksum.md5 2>&1 |\
    awk -F'[:/]' '/FAILED/{system("wget http://example.com/"$(NF-1))}'

Upvotes: 2

Arjun Mathew Dan
Arjun Mathew Dan

Reputation: 5298

Like this:

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

Upvotes: 1

Related Questions