I am trying to find a way to transform a script to a bash one-liner. I have a txt file of the name of pdf files and I want to download them from the internet.
file1
file2
file3
The files are located on a remote server directory.
I am doing the job using a simple script file, say script.sc.
#! /bin/bash
file=$1.pdf
link=https://server-dir/doc/$1
curl -o $file $link
and the by using cat
and xargs
cat list_of_filenames.txt > xargs -I % script.sc %
I am trying - mainly to increase my understanding of the shell - to find a way of accomplishing the same functionality without using the script, but only through the shell and the usually installed utilities (awk? sed?)
You can extend the use of the -I
flag of xargs
, like so:
<list_of_filenames.txt xargs -I @ curl https://server-dir/doc/@.pdf -o @.pdf
The list of filenames is piped into the xargs
command. The command goes over the list and runs curl
on each of them. The I
flag takes care of substituting the placeholder to create the desired URL and output destination.