I have the following bash command which fetches and block XML from a single column in mysql and feeds it into xmllint to prettify it.
mysql --format csv --skip-column-names -e "select xmldata from mytable limit 1;" | xmllint --format -
So far so good, but it only works for one row at a time. I would like to adapt this so each line in the SQL query output is fed in to a separate call to xmlint.
I know this can be done with a loop in a bash script — but I'd like to do it in a one-liner if possible. Supposedly this can be done with xargs but I can't figure it out.
Best Answer
Split for easier reading, obviously you don't need to. The
<<<$line
is aherestring
, which feeds the contents of$line
toxmllint
as stdin.