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

沒有留言:

張貼留言

[ FP with Java ] Ch3 - Making Java more functional - Part1

Preface This chapter covers *  Making standard control structures functional *  Abstracting control structures *  Abstracting iter...