原檔案
# cat tablelist.txt
Schema | Name | Type | Owner
--------+---------------------+----------+------------
public | dept | table | postgres
public | job | table | postgres
public | client | table | postgres
清單内容
#cat tablelist.txt|grep 'public'
列印列去除前後一個或若幹個空格或tab制表符
#cat tablelist.txt|grep 'public'|awk -F '|' '{print $2}'|awk '{gsub(/^[ \t]+|[ \t]+$/,"")};1'
dept
job
client
添加前後字元
# cat tablelist.txt|grep 'public'|awk -F '|' '{print $2}'|awk '{gsub(/^[ \t]+|[ \t]+$/,"")};1'|sed 's/^/grant all privileges on /g'|sed 's/$/ to dbauser;/g'
grant all privileges on dept to dbauser;
grant all privileges on job to dbauser;
grant all privileges on client to dbauser;
cat tablelist.txt|awk -F '|' '{print $2}'|grep 'ape*'|awk '{gsub(/^[ \t]+|[ \t]+$/,"")};1'|sed 's/^/grant all privileges on /g'|sed 's/$/ to jobinsight;/g'
顯示所有檔案》列印第二列》 列印帶有ape的行 》去除字元前後一個或者若幹個空格或者制表符》添加清單的前導》添加清單的字尾字元
本文轉自 pgmia 51CTO部落格,原文連結:http://blog.51cto.com/heyiyi/846504