- 求職 : Linux運維
- 論壇徽章:
- 10
|
有一個文件1.txt和一個腳本1.sh, 想讓腳本1.sh讀取1.txt中內(nèi)容作為sql中的2個參數(shù),然后通過sql查詢出對應(yīng)的值并保存;
目前只知道遍歷1.txt所有的值,sql查詢結(jié)果中只有最后一個記錄的值;前面的都沒法保存下來;
獲取1.txt中內(nèi)容時,必須是1對應(yīng)a,2對應(yīng)b這樣對應(yīng),不能1對應(yīng)b、c、d、e. 也就是共取出5對,然后查詢五次;該怎么做呢?謝謝!
一、1.txt中的內(nèi)容,其中數(shù)字為id,字母為seg
1 a
2 b
3 c
4 d
5 e
二、1.sh
for id in `awk '{print $1}' 1.txt`
do
echo $id
done
for seg in `awk '{print $2}' 1.txt`
do
echo $seg
done
sql="select * from tb1 a where a.id='' and a.seg=''"
mysql -h0 uhello -P3306 -phello123 -e "{$sql}" >> /usr/local/data.txt
|
|