AWK原理及命令和文件输入

一,awk简介1,awk是3个姓氏的首字母,代表该语言的3个作者,awk的版本有很多,包括:旧版awk,新版awk(nawk),GNU awk(gawk)等。awk程序有awk命令,括在引号或写在文件中的指令以及输入文件这几个部分组成。2,[root@rhel helinbash]# which awk/bin/awk[root@rhel helinbash]# which gawk/bin/gawk[root@rhel helinbash]# ls -l /bin/awk /bin/gawklrwxrwxrwx 1 root root 4 Oct 10 2013 /bin/awk -> gawk-rwxr-xr-x 1 root root 320416 Jan 15 2007 /bin/gawk[root@rhel helinbash]# 注:以后的例子都是采用gawk命令

AWK简介及使用实例

AWK 简介和例子

Shell脚本之AWK文本编辑器语法

正则表达式中AWK的学习和使用

文本数据处理之AWK 图解

二,awk工作原理1,,以下内容的names文件名举例按步骤解析awk的处理过程(1)vim namesTom Savage 100Molly Lee 200John Doe 300(2)[root@rhel helinbash]# cat names.txt | cut -d ‘ ‘ -f 2

Savage Lee

[root@rhel helinbash]# cat names.txt | cut -d ‘\t’ -f 2 cut: the delimiter must be a single characterTry `cut –help’ for more information.[root@rhel helinbash]# (3)[root@rhel helinbash]# gawk ‘{ print $1,$3 }’ names.txt Tom 100Molly 200John 300 [root@rhel helinbash]#

[root@rhel helinbash]# gawk ‘{ print $1 $3 }’ names.txt

Tom100Molly200John300[root@rhel helinbash]#

2,原理图FS:Field separator(分隔符)OFS:Output Field Separator

第三步:awk中print命令打印字段;{print $1,$3} 只取有用的第一段和第三段;在打印时$1和$3之间由空格间隔。“,”逗号是一个映射到内部的输出字段分隔符(OFS),OFS变量缺省为空格,逗号在输出时被空格替换。接下来,awk处理下一行数据,直到所有的行处理完。

更多详情见请继续阅读下一页的精彩内容:

明天的希望,让我们忘了今天的痛苦

AWK原理及命令和文件输入

相关文章:

你感兴趣的文章:

标签云: