Quantcast
Viewing all articles
Browse latest Browse all 743

awkでデリミタ(区切り文字)を複数指定する

awkでデリミタ(区切り文字)を複数指定する場合は、「[](カギカッコ)」で囲ってやる事で-Fで指定することができる。
例えば、以下の例だと「,」と「-」で列を区切るように指定している。

awk -F'[:-]' '{…}'

Image may be NSFW.
Clik here to view.
20160122_000004

[root@localhost ~]# cat /tmp/test.file
aaaaa,111-11,super,66666661
bbbbb,222-22,wonder,66666662
ccccc,333-33,dorderar,66666663
ddddd,44-444,atacker,66666664
eeeee,55-55,pepsi,66666665
fffff,66-666,papet,66666666
ggggg,777-77,dagashikasi,66666667
hhhhh,888-88,goemon,66666668

[root@localhost ~]# awk -F'[,-]' '{print $2}' /tmp/test.file
111
222
333
44
55
66
777
888

[root@localhost ~]# awk -F'[,-]' '{print $3}' /tmp/test.file
11
22
33
444
55
666
77
88

 

Image may be NSFW.
Clik here to view.
AWK実践入門 (Software Design plus)
AWK実践入門 (Software Design plus)

Viewing all articles
Browse latest Browse all 743