第七色在线视频,2021少妇久久久久久久久久,亚洲欧洲精品成人久久av18,亚洲国产精品特色大片观看完整版,孙宇晨将参加特朗普的晚宴

為了賬號(hào)安全,請(qǐng)及時(shí)綁定郵箱和手機(jī)立即綁定
已解決430363個(gè)問(wèn)題,去搜搜看,總會(huì)有你想問(wèn)的

如何使用linux cli忽略csv文件中的任何特定列數(shù)據(jù)?

如何使用linux cli忽略csv文件中的任何特定列數(shù)據(jù)?

慕慕森 2021-04-14 21:18:37
我有9列喜歡c1 c2 c3 c4 c5 c6 c7 c8 c9,我想關(guān)注的價(jià)值c1 c2 c3 c4 c5 and c9。列具有CSV格式的以下數(shù)據(jù)。如何通過(guò)CLI在Linux中執(zhí)行此操作?請(qǐng)幫忙樣本數(shù)據(jù)123,B006195,T,O,INDIVIDUAL,25^5820200^,2018-04-25,13,NEW12,C06195,T,O,INDIVIDUAL,25^5820200^,2018-04-25,13,NEW12345,B00619,T,O,IND,25^5820200^,2018-04-25,13,OLD我嘗試使用 cat file.csv | awk '{print $1,$2,$3,$4,$5}' > newfile
查看完整描述

2 回答

?
牛魔王的故事

TA貢獻(xiàn)1830條經(jīng)驗(yàn) 獲得超3個(gè)贊

以下解決方案可能對(duì)您有所幫助,您需要在awknamed變量中提供字段編號(hào)fields并可以打印出來(lái)。


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

現(xiàn)在也添加非單一襯里形式的解決方案。


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

上面的代碼說(shuō)明:


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.



查看完整回答
反對(duì) 回復(fù) 2021-04-16
  • 2 回答
  • 0 關(guān)注
  • 383 瀏覽
慕課專欄
更多

添加回答

舉報(bào)

0/150
提交
取消
微信客服

購(gòu)課補(bǔ)貼
聯(lián)系客服咨詢優(yōu)惠詳情

幫助反饋 APP下載

慕課網(wǎng)APP
您的移動(dòng)學(xué)習(xí)伙伴

公眾號(hào)

掃描二維碼
關(guān)注慕課網(wǎng)微信公眾號(hào)