主要实现如下几步:
1.将字符串”delete from table_name;" 写入到临时文件“/tmp/tmpscript.sql"
2. 将已知文件”/file1/file2/default.sql"中含有字符串“insert into table name”的行写入到临时文件“/tmp/tmpscript.sql"中
3. 一旦文件写完,就调用命令“dbIsql –f /tmp/tmpscript.sql”执行
4. 删除临时文件“/tmp/tmpscript.sql"
第1个回答 2011-05-21
#!/bin/bash
table_name= #指定表名
echo "delete from $table_name;" > /tmp/tmpscript.sql
grep "insert into $table_name" /file1/file2/default.sq >> /tmp/tmpscript.sql
dbIsql -f /tmp/tmpscript.sql
rm -f /tmp/tmpscript.sql
exit 0
#end追问
table_name= #指定表名
echo "delete from $table_name;" > /tmp/tmpscript.sql
grep "insert into $table_name" /file1/file2/default.sq >> /tmp/tmpscript.sql
dbIsql -f /tmp/tmpscript.sql
rm -f /tmp/tmpscript.sql
exit 0
#end追问
What is the difference between the following two shell statement?
grep "insert into $table_name" /file1/file2/default.sq >> /tmp/tmpscript.sql
grep "insert into $table_name" /file1/file2/default.sq | tee -a /tmp/tmpscript.sql
| tee -a 表示将信息输出到标准输出(终端屏幕)的同时,也写入后面的文件中(其中,-a表示追加)
本回答被网友采纳