awk - Bash: Set theory -


i have following tab-delimited table:

      b   c   d   e   f   g   h     j zo1     x1  x2  x3          x4      x5  x6 zo2 x7  x8  x9  x10     x11 x12 x13 x14 x15 zo3 x16 x17 x18 x19         x20     x21 x22 zo4     x23 x24 x25         x26     x27 x28 zo5     x29 x30                          zo6     x31 x32 x33 x34 x35 x36 x37 x38 x39 zo7 x40 x41 x42 x43 x44 x45 x46 x47 x48 x49 zo8     x50 x51 x52         x53     x54 x55 

(x## random string)

and want extract values in column #1, fulfill condition. exemplary condition be: retrieve values (column1), have non-empty value in columns b,c,d,g,i,j , empty values in remaining columns a,e,f,h.

so example output be:

z01 z04 z08 

edit: sorry poor input. below semicolon-delimited table; real input tab-delimited

;a;b;c;d;e;f;g;h;i;j zo1;;x1;x2;x3;;;x4;;x5;x6 zo2;x7;x8;x9;x10;;x11;x12;x13;x14;x15 zo3;x16;x17;x18;x19;;;x20;;x21;x22 zo4;;x23;x24;x25;;;x26;;x27;x28 zo5;;x29;x30;;;;;;; zo6;;x31;x32;x33;x34;x35;x36;x37;x38;x39 zo7;x40;x41;x42;x43;x44;x45;x46;x47;x48;x49 zo8;;x50;x51;x52;;;x53;;x54;x55 

i one, it'll run if copy , paste whole bash, comments , all.

tail -n +2 file              `# grab bit of file car about` \ |  sed 's/;/|;/'           `# protect first column`               \ |  sed 's/;[^;][^;]*/1/g' `# change filled values 1`      \ |  sed 's/;/0/g'            `# change empty values 0` 

the output of command looks this:

 zo1|0111001011  zo2|1111011111  zo3|1111001011  zo4|0111001011  zo5|0110000000  zo6|0111111111  zo7|1111111111  zo8|0111001011 

so can set pattern i'm looking for.

tail -n +2 file              `# grab bit of file car about` \ |  sed 's/;/|;/'           `# protect first column`               \ |  sed 's/;[^;][^;]*/1/g' `# change filled values 1`      \ |  sed 's/;/0/g'            `# change empty values 0`           \ |  grep "|0111001011"        `# grab match want`                \ |  sed  's/|.*//'            `# clear out garbage` 

then id g eneralize function

>> function table_match () {     cat                          `# grab stdin`                     \     |  sed 's/;/|;/'           `# protect first column`           \     |  sed 's/;[^;][^;]*/1/g' `# change filled values 1`  \     |  sed 's/;/0/g'            `# change empty values 0`       \     |  grep "|${1}"              `# grab match want`            \     |  sed  's/|.*//'            `# clear out garbage`; }   >> tail -n +2 file | table_match 0111001011 zo1 zo4 zo8 

i can other stuff ... dot wild card ... kleene star ... nifty.

>> tail -n +2 file | table_match .......011 zo1 zo2 zo3 zo4 zo5 zo6 zo7 zo8  >> tail -n +2 file | table_match 01* zo1  zo4  zo5  zo6  zo8  

Comments

Popular posts from this blog

javascript - Create a stacked percentage column -

Optimising Firebase database by automatically overwriting data -

javascript - Angular UI-Grid customTemplate directive causing rows to load slowly/? -