I have a perl script that writes out an array filled with integers to stdout, each on a separate line. So I would get output like:
412
917
1
etc
What I would like to do is be able to pipe the output of this script into xargs, and make a curl call using each integer. Something like this:
cat input.json | ./jsonValueExtracter.pl -s exampleId | xargs curl http://brsitv01:8080/exampleId/$1 > example$1.json
Below is an excerpt of a simple script I am using.
my @values;
while(<STDIN>) {
chomp;
s/\s+//g; # Remove spaces
s/"//g; # Remove single quotes
push @values, /$opt_s:(\w+),?/g;
}
print join(" \n",@values);
However, this doesn't work the way I would expect. When I run the following command:
cat input.json | perl jsonValueExtracter.pl -s exampleId | xargs echo http://brsitv01:8080/exampleId/$1
I get the output:
http://brsitv01:8080/exampleId/ 412 917 1
Is there anything special I need to do to use the output of a perl script in xargs?
Thanks