2015年5月28日 星期四

[Linux 常見問題] How to use “:” as awk field separator?

Source From Here 
Question 
Given following command: 
$ echo -e "1:2:3:4\r\n5:6:7:8" | awk '{print $1}'
1:2:3:4
5:6:7:8

I expected to have output: 
1
5

How-To 
"-F" is a command line argument not awk syntax, try: 
$ echo -e "1:2:3:4\r\n5:6:7:8" | awk -F ':' '{print $1}'
1
5

Supplement 
Awk Introduction Tutorial – 7 Awk Print Examples

沒有留言:

張貼留言

[ Python 文章收集 ] List Comprehensions and Generator Expressions

Source From  Here   Preface   Do you know the difference between the following syntax?  view plain copy to clipboard print ? [x  for ...