I have a multi-line string coming from another program that I want to convert to a SQL command. I was hoping that printf could help me, but it doesn't seem to work:
echo -e '1\n2\n3'|printf 'SELECT %s INTO MyTable'
I was hoping to see:
SELECT '1 2 3' INTO MyTable
But I got:
SELECT INTO MyTable
How can I get the %s to read stdin?
Use xargs to transform stdin to program arguments:
echo -n -e '1\n2\n3' |xargs -0 printf 'SELECT %s INTO MyTable'
Give this a try:
printf_stdin() { local stdin; read -d '' -u 0 stdin; printf "$@" "$stdin"; } echo -e '1\n2\n3' | printf_stdin 'SELECT %s INTO MyTable'
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With