设为首页 - 加入收藏 ASP站长网(Aspzz.Cn)- 科技、建站、经验、云计算、5G、大数据,站长网!
热搜: 创业者 手机 数据
当前位置: 首页 > 服务器 > 搭建环境 > Linux > 正文

Awk by Example--转载

发布时间:2021-02-04 06:16 所属栏目:118 来源:网络整理
导读:原文地址: 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:

原文地址:

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

                        

(编辑:ASP站长网)

网友评论
推荐文章
    热点阅读