awk 学习记录1
2017-04-13 23:24
211 查看
awk 使用的情形
直接在命令行下使用如某文件为test.txt
现在在使用awk打印空行
可以这样
cat test.txt
文件内容如下
hello world hello world hello world hello world hello world hello world world world world xxxddsdad 总用量 24 -rwxrwxr-x 1 oc oc 114 Apr 11 01:09 expcect_test.sh -rw-rw-r-- 1 oc oc 6 Apr 12 20:27 file1 -rw-rw-r-- 1 oc oc 6 Apr 12 20:27 file2 -rw-rw-r-- 1 oc oc 206 Apr 11 00:35 read.sh -rw-rw-r-- 1 oc oc 102 Apr 13 21:38 test.txt -rw-rw-r-- 1 oc oc 112 Apr 11 01:17 until_test.sh
awk '/^$/{print "this is a blank line"}' test.txt
this is a blank line this is a blank line
将awk写入文件,再使用awk调用某文件
cat scr.awk
#! /bin/awk -f /^$/{print "this is a blank line"}
awk -f scr.awk test.txt
或者加执行权限
chmod a+x ./scr.awk ./scr.awk test.txt
awk 记录和域
awk认为文件为结构化的,以行为记录,每行的字符串为域,域间用空格或者tab键等进行分割,这些分割域的符号为分割符比如 有一个名为test.txt的文件,其内容是
先使用awk打印全部域,使用$0
先打印第1列和第4列,使用1和4
指定域分割符,使用-F
先更改文件test.txt,在每行test2后增加一个tab
可以看出以tab键分割的域1为test1 和test2
域2 为test3和test4
相关文章推荐
- awk学习记录
- awk的基本使用--我的学习记录
- awk 学习记录
- awk学习记录
- awk日志分析学习记录
- awk学习记录
- awk实例操作学习记录
- awk学习随常记录
- c#学习记录
- .NET WEB SERVICES 学习记录(三)
- Gtk2 - perl 学习记录
- ADO.net学习记录 (一)
- .net学习点滴记录
- SED,AWK学习笔记Part 1-----利用正则表达式进行文本匹配
- C#学习记录
- .NET WEB SERVICE 学习记录
- ADO.net学习记录
- BatchUpdata 学习记录
- 《千万别学英语》--第二阶段学习记录
- 记录hibernate 3学习过程中的报错(未完成)