linux合并csv文件不包含头部,如何使用linux cli忽略csv文件中的任何特定列数据?...

以下解决方案可能对您有所帮助,您需要在awknamed变量中提供字段编号fields并可以打印出来。

awk -F, -v fields="1,2,3,4,5,9" 'BEGIN{num=split(fields, array,",")} {for(i=1;i<=num;i++){printf("%s%s",$array[i],i==num?ORS:OFS)}}' OFS=,   Input_file

现在也添加非单一衬里形式的解决方案。

awk -F, -v fields="1,2,3,4,5,9" '

BEGIN{

num=split(fields, array,",")}

{

for(i=1;i<=num;i++){

printf("%s%s",$array[i],i==num?ORS:OFS)}}

' OFS=,   Input_file

上面的代码说明:

awk -F, -v fields="1,2,3,4,5,9" '              ##Setting field seprator as comma here with -F. Setting variable named fields with values of fields which we need.

BEGIN{                                         ##Starting BEGIN section here for awk which will be executed before reading the Input_file.

num=split(fields, array,",")}                ##using split to split the variable fields into array named array and creating variable num which will have number of element of array.

{

for(i=1;i<=num;i++){                         ##Starting a for loop here which starts from variable named i value from 1 to till value of variable num.

printf("%s%s",$array[i],i==num?ORS:OFS)}}  ##Printing value of array[i] and then $array[i] will print the field value in current line too. Then checking condition variable i value equal to variable num then print new line else print space with OFS.

' OFS=,  Input_file                            ##Mentioning the Input_file name here.

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值