GNU工具箱

来源:互联网 发布:中国体育网络电视台 编辑:程序博客网 时间:2024/05/17 08:20

转自:http://blogread.cn/it/article/330?f=wb


内容摘要:
GNU很推崇“工具箱”哲学:很多复杂的问题都可以通过几个更简单的工具通过一定的组合加以解决的。

shell 脚本本身的一些变量: $_ shell环境名称 如 /bin/sh ; $0 shell脚本本身,如 test.sh ; $1 $2 ..$9 命令行参数 test.sh -a -b 的$1 = -a $2 = -b

编辑器:VI pico emacs

vi中显示行号: :set nu
去文件尾部:G
去行尾 $
添加 i a
删除 x

脚本和行文字处理

给文件批量加前缀:
先用awk生成命令列表:
ls -1 *|awk '{print "uniq -c "$1" pre_"$1"|sort -rn"}' > batch_rename.sh

然后执行生成的脚本:
sh batch_rename.sh 

我的每月访问TOP10 统计脚本:
awk -F '\t' '{print $4}' 2004_2.txt| grep chedong.com/tech/|sort |uniq -c|sort -rn|head -10 
awk -F '\t' 用TAB分割;
grep chedong.com/tech 只列出笔记目录下的文档;
sort 排序
uniq -c 汇总计数
sort -rn 按数值排序
head -10 TOP 10

我的每月来源TOP10统计脚本:
grep --binary-files=text chedong.com 2004_2.txt |awk -F '\t' '{print $3}'| awk -F '/' '{print "http://"$3}'|grep -v chedong.com|sort|uniq -c |sort -rn|head -10
grep --binary-files=text 强制按text文本处理
awk -F '\t' 用TAB分割;
awk -F '/' 获得域名;
grep -v chedong.com 排除自身网站;
sort 排序
uniq -c 汇总计数
sort -rn 按数值排序
head -10 TOP 10

grep 打印上下文5行
grep -A 5 -B 5 sometext my.file

去掉#开头的注释,如:apache的httpd.conf
grep -v "#" filename

打印大文档中的某一行:
sed -n 1234p access_log

将每4行数据变成一行
pr -a -J -T --columns=4 source.log 
-a 横向输出 
-J 合并成行 
-T 忽略页头和页尾 
--columns=4 每4个单元一次


原创粉丝点击