awk 的分隔符

awk 分隔符的使用:

1.awk -F分隔符

2.是用分隔符变量 awk -v FS='分隔符'

3.输出分隔符变量 awk -v OFS='分隔符'

4.输出变量用','分割后将割开显示  awk '{print $1,$2}'

5.输出变量用' '分割后将连接显示 awk '{print $1 $2}'

LM-SHC-16507744:Desktop yanwxu$ cat testd
123#ruby#3#abc
456#rechel#25#def
789#wang#30#ghi
LM-SHC-16507744:Desktop yanwxu$ awk -F# '{print $1,$2}' testd
123 ruby
456 rechel
789 wang
LM-SHC-16507744:Desktop yanwxu$ awk -v FS='#' '{print $1,$2}' testd
123 ruby
456 rechel
789 wang
LM-SHC-16507744:Desktop yanwxu$ awk -v FS='#' OFS='+++++' '{print $1,$2}' testd
awk: syntax error at source line 1
 context is
	 >>> OFS=++++ <<<
awk: bailing out at source line 1
LM-SHC-16507744:Desktop yanwxu$ awk -v FS='#' -v OFS='+++++' '{print $1,$2}' testd
123+++++ruby
456+++++rechel
789+++++wang
LM-SHC-16507744:Desktop yanwxu$ awk -F# '{print $1,$2}' testd
123 ruby
456 rechel
789 wang
LM-SHC-16507744:Desktop yanwxu$ awk -F# '{print $1  $2}' testd
123ruby
456rechel
789wang

 

你可能感兴趣的:(Linux)