linux 中awk命令指定读入分隔符

 

001、 -F 指定

[root@pc1 test01]# ls
a.txt
[root@pc1 test01]# cat a.txt
a:b:c
3:8:k
f:6:3
[root@pc1 test01]# awk -F ":" '{print $1}' a.txt   
a
3
f

 

002、-v FS变量指定

[root@pc1 test01]# ls
a.txt
[root@pc1 test01]# cat a.txt
a:b:c
3:8:k
f:6:3
[root@pc1 test01]# awk -v FS=":" '{print $1}' a.txt
a
3
f

 

003、直接使用FS指定

[root@pc1 test01]# ls
a.txt
[root@pc1 test01]# cat a.txt
a:b:c
3:8:k
f:6:3
[root@pc1 test01]# awk '{print $1}' FS=":" a.txt
a
3
f

 

004、错误指定方法

[root@pc1 test01]# ls
a.txt
[root@pc1 test01]# cat a.txt
a:b:c
3:8:k
f:6:3
[root@pc1 test01]# awk '{FS = ":"; print $1}' a.txt
a:b:c
3
f

 

005、

[root@pc1 test01]# ls
a.txt
[root@pc1 test01]# cat a.txt
a:b:c
3:8:k
f:6:3
[root@pc1 test01]# awk '{FS = ":"; $0 = $0; print $1}' a.txt
a
3
f

 。

 

posted @ 2023-09-08 12:28  小鲨鱼2018  阅读(78)  评论(0编辑  收藏  举报