Processing MySQL result in bash

后端 未结 3 367
抹茶落季
抹茶落季 2021-01-22 07:05

I\'m currently having a already a bash script with a few thousand lines which sends various queries MySQL to generate applicable output for munin.

Up until now the resul

3条回答
  •  庸人自扰
    2021-01-22 07:35

    My example is not Bash, but I'd like to point out my parameters at invoking the mysql command, they surpress the boxing and the headers.

    #!/bin/sh
    
    mysql dbname -B -N -s -e "SELECT * FROM tbl" | while read -r line
    do
      echo "$line" | cut -f1   # outputs col #1
      echo "$line" | cut -f2   # outputs col #2
      echo "$line" | cut -f3   # outputs col #3
    done
    

提交回复
热议问题