20. mysql
mysql --host=127.0.0.1 --port=3306 --database=test --user=test --password=test --default-character-set=utf8
21. 脚本求两个文件的相同集合
test1 test2
1 2
2 3
3 4
cat test1 test2 | sort | uniq -d (result: 2 3)
cat test1 test2 | sort | uniq -c | wc -l (result:4) 统计所有出现数字的个数
cat test1 test2 | sort | uniq -c |awk -F ‘ ‘ ‘{print $1}‘|grep 2|wc -l 连续出现两次的个数
22. 生成1到10的数字
for i in `seq 10`
do
echo $i
done
23. 通过脚本生成sql语句
1
2
3 |
date =` date
-d yesterday +%Y-%m-%d` outputFileName= "sql.${date}" cat test1 | awk ‘BEGIN{datecmd="date -d yesterday +%Y-%m-%d";datecmd|getline dateStr}{print "INSERT INTO test (dayString, num1, num2, num3) VALUES (‘ \ ‘‘ "dateStr "‘\‘‘, 0, " $1 ", " $1 ") ON DUPLICATE KEY UPDATE num2 = " $1 ", num3 = " $1 ";" }‘ > ${outputFileName} |
生成的结果:INSERT INTO test (dayString, num1, num2, num3) VALUES
(‘2014-06-07‘, 0, 1, 1) ON DUPLICATE KEY UPDATE num2 = 1, num3 = 1;
INSERT
INTO test (dayString, num1, num2, num3) VALUES (‘2014-06-07‘, 0, 2, 2) ON
DUPLICATE KEY UPDATE num2 = 2, num3 = 2;
INSERT INTO test (dayString, num1,
num2, num3) VALUES (‘2014-06-07‘, 0, 3, 3) ON DUPLICATE KEY UPDATE num2 = 3,
num3 = 3;
插入数据库的话可以用脚本:mysql -h127.0.0.1 -P3306 -utest -ptest --database testdb < ${outputFileName}
24. awk
1)统计次数
test3
a=优秀
b=良好
b=优秀
c=良好
cat test3 | awk -F "=" ‘{sum[$1]+=1}END{for(i in sum)print sum[i],i}‘
cat test3 | awk -F "=" ‘{sum[$2]+=1}END{for(i in sum)print sum[i],i}‘
result1: result2: result3:
2
优秀
1
a
a=优秀
2
良好
2
b
b=良好
1 c c=及格
2) 提取20:1:0:0:{a=优秀, b=良好, c=及格} 里面的{}数据
cat test4 | awk ‘BEGIN {FS=":"} {print $5}‘ | sed -e "s/[\{\}]//g" | awk ‘{split($0, items, ", ");for(it in items){print items[it]}}‘
原文地址:http://www.cnblogs.com/cstar/p/3775798.html