unix - Now I have following code in shell script, can someone help me fix it and understand the code? -


i new shell script new stackoverflow. :) , need guys

cat header_list.txt id  cat test123123.csv name              id           portfolio counterparty cards id  process *theoretical model  issue date murex_01576184  :murex_01576184 :hk-aufwd   h-ccbc_pm   20229   metals  :bns forex  4/27/2016 murex_01576194  :murex_01576194 :hk-aufwd   h-ccbc_pm   20229   metals  :bns forex  4/27/2016 murex_02351193  :murex_02351193 :hk-aufwd   h-ccbc_pm   20229   metals  :bns forex  10/31/2016 murex_02351197  :murex_02351197 :hk-aufwd   h-ccbc_pm   20229   metals  :bns forex  10/31/2016 murex_02351203  :murex_02351203 :hk-aufwd   h-ccbc_pm   20229   metals  :bns forex  10/31/2016 murex_02351207  :murex_02351207 :hk-aufwd   h-ccbc_pm   20229   metals  :bns forex  10/31/2016    # here main code awk 'nr==fnr{             cols=cols (cols?"|":"")$1             next         }   fnr==1{             (i=1;i<=nf;i++)              if (match($i,cols))              ar[++n]=i        }         {            (i=1;i<=n;i++)             printf (i<n)? $(ar[i])  fs : $(ar[i])            printf "\n"         }' fs=","  header_list.txt test123123.csv  expected output: id :murex_01576184 :murex_01576194 :murex_02351193 :murex_02351197 :murex_02351203 :murex_02351207  actual   id             cards id :murex_01576184 20229 :murex_01576194 20229 :murex_02351193 20229 :murex_02351197 20229 :murex_02351203 20229 :murex_02351207 20229 

in example, returns columns header contains "id". thinking it's nr==fnr part causing problem. couldn't understand means

 cols=cols (cols?"|":"")$1  next 

could me understand code? if possible, fix code too?

the problem match method takes regex second argument.

change if normal comparison (==) should help.


Comments

Popular posts from this blog

asynchronous - C# WinSCP .NET assembly: How to upload multiple files asynchronously -

aws api gateway - SerializationException in posting new Records via Dynamodb Proxy Service in API -

asp.net - Problems sending emails from forum -