问题描述
对不起,如果这是不可能的AWK的事,但这个事情我可以用AWK想到的。
sorry if this is impossible to do with AWK, but this is something I can think of with AWK.
我有了一个大标题部分约10列的CSV文件(制表符分隔)。内容是这样的:
I have a CSV file (tab delimited) that has about 10 columns with a big header section. The content is like this:
col1 col2 col3 col4 col5 col6 col7 col8 col9 col10
我并不需要通过col1-9过滤,而只需要通过线看col10线。 col10的每一行中的内容是这样的。
I don't need to filter by col1-9, but only need to look at col10 line by line. The content in each row of col10 is like this
int1/int2: int3,int4: int5: int6
我的过滤条件为:如果INT3 + INT4> = 30
,我会打印出来到一个新的CSV文件,否则筛选出来(没有打印)
My filtering condition is: if int3 + int4 >= 30
, I'll print it out to a new csv file, otherwise filter it out (no print).
这可能与AWK做与shell脚本(逐行读取?)组合?非常感谢您阅读我的问题
Is this possible to do with AWK in combination with shell scripts (read line by line?)? thanks a lot for reading my question
推荐答案
试试这个
awk -F'\t' -v OFS='\t' '{ t = $10
split(t,x,":")
split(x[2],a,",")
}(a[1]+a[2])>=30' oldcsv > newcsv
或较短的:
awk -F'\t' -v OFS='\t' '{t=$10; split(t,a,/[:,]/)}(a[3]+a[2])>=30' oldcsv > newcsv
没有测试,但应该工作,如果$ 10的格式是固定的。
didn't test, but should work, if the format of $10 is fixed.
这篇关于用awk处理一个CSV(制表符分隔)一行一行的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!