awk - Using matching entries (shell scripting) -


i have 2 .csv files of same structure

enstgug00000000001,c2cd2l enstgug00000000002,dpagt1 enstgug00000000003,egr1 enstgug00000000004,reep2 enstgug00000000005, enstgug00000000006,pias2 enstgug00000000007,kdm3b enstgug00000000008, enstgug00000000010,hmbs enstgug00000000011, 

and

enstgug00000000001, enstgug00000000002,dpagt1 enstgug00000000003,egr1 enstgug00000000004,reep2 enstgug00000000005, enstgug00000000006,pias2 enstgug00000000007,kdm3b enstgug00000000008,loc100218573 enstgug00000000010,hmbs enstgug00000000011, 

i want find elements in 1st column of 1st file 2nd column empty, , search corresponding in 2nd column of 2nd file.

so output be

enstgug00000000001,c2cd2l enstgug00000000002,dpagt1 enstgug00000000003,egr1 enstgug00000000004,reep2 enstgug00000000005, enstgug00000000006,pias2 enstgug00000000007,kdm3b enstgug00000000008,loc100218573 enstgug00000000010,hmbs enstgug00000000011, 

this way can have 1st file complete possible.

assuming files line line line:

awk '{getline s < "file2.csv"; split( s, a, ",")}        !$2 && a[2] { $2 = a[2] }1' fs=, file1.csv 

this not remotely robust, , if files don't match worthless, gives somewhere start.

it's self-explanatory... awk nature reads input file 1 line @ time. each time reads line, performs commands in script. in case, reads 1 line file2.csv , splits on ,. checks see if second field of line read file1.csv evaluates boolean false (so if have entries integer 0, may overwritten) , second field in line file 2 non-zero. if that's true, assigns field file2 2nd field of current input line. outputs line.


Comments

Popular posts from this blog

ios - MKAnnotationView layer is not of expected type: MKLayer -

ZeroMQ on Windows, with Qt Creator -

unity3d - Unity SceneManager.LoadScene quits application -