加入收藏 | 设为首页 | 会员中心 | 我要投稿 瑞安网 (https://www.ruian888.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 服务器 > 搭建环境 > Linux > 正文

Awk by Example--转载

发布时间:2021-02-06 15:24:08 所属栏目:Linux 来源:网络整理
导读:原文地址: http://www.funtoo.org/Awk_by_Example,_Part_1?ref=dzone http://www.funtoo.org/Awk_by_Example,_Part_2 http://www.funtoo.org/Awk_by_Example,_Part_3 halt7 operator11 root0 shutdown6 sync5 bin1 ....etc. username: halt uid:7 username:
副标题[/!--empirenews.page--]

原文地址:

http://www.funtoo.org/Awk_by_Example,_Part_1?ref=dzone

http://www.funtoo.org/Awk_by_Example,_Part_2

http://www.funtoo.org/Awk_by_Example,_Part_3

halt7 
operator11 
root0 
shutdown6 
sync5 
bin1 
....etc. 

username: halt     uid:7 
username: operator uid:11 
username: root     uid:0 
username: shutdown uid:6 
username: sync     uid:5 
username: bin      uid:1 
....etc. 

BEGIN { 
        FS=":" 
} 
{ print $1 } 

#!/usr/bin/awk -f
BEGIN {
    FS=":"
}
{ print $1 }

/foo/ { print }

/[0-9]+.[0-9]*/ { print }

$1 == "fred" { print $3 }

$5 ~ /root/ { print $3 }

{ 
    if ( $5 ~ /root/ ) { 
        print $3 
    }
}

{
    if ( $1 == "foo" ) {
        if ( $2 == "foo" ) {
            print "uno"
        } else {
            print "one"
        }
    } else if ($1 == "bar" ) {
        print "two"
    } else {
        print "three"
    }
}

! /matchme/ { print $1 $3 $4 }

{
    if ( $0?!~ /matchme/ ) {
        print $1 $3 $4
    }
}

( $1 == "foo" ) && ( $2 == "bar" ) { print } 

BEGIN { x=0 } 
/^$/  { x=x+1 } 
END   { print "I found " x " blank lines.?:)" } 

x="1.01" 
# We just set x to contain the *string* "1.01" 
x=x+1 
# We just added one to a *string* 
print x 
# Incidentally,these are comments?:) 

2.01

{ print ($1^2)+1 }

FS="t+"

FS="[[:space:]]+"

FS="foo[0-9][0-9][0-9]"

NF == 3 { print "this particular record has three fields: " $0 }

{
    if ( NF > 2 ) {
        print $1 " " $2 ":" $3 
    }
}

(NR < 10 ) || (NR > 100) { print "We are on record number 1-9 or 101+" }
{
    #skip header
    if ( NR > 10 ) {
        print "ok,now for the real information!"
    }
}

Jimmy the Weasel
100 Pleasant Drive
San Francisco,CA 12345

                                                

(编辑:瑞安网)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

热点阅读