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 文章收集 ] A tutorial on python-daemon – or – Why doesn’t python-daemon have any documentation?

Source From  Here   Introduction   A few weeks ago I needed to create a daemon for a school project. I had never really dealt with daemons b...