awk - i have a file all field are same then print line in bash? field is not fix -


i have 1 file. plz leave $1. if field $2..$x same print line. other wise not. no. of field not fix. in advance

input.txt  1;do;do;do;do;do;do;  2;do;do;do;do;do;to;  3;to;do;do;to;do;  4;do;do;do;do;to;  5;do;do;to;do;do;  6;do;do;do;do;do;  7;do;to;do;do;to;  8;do;to;to;do;  9;to;to;to;to; output:  1;do;do;do;do;do;do;  6;do;do;do;do;do;  9;to;to;to;to; 

here's solution using awk

awk -f ';' '{same=1; (i=3;i<nf;i++) { if ($i != $2) { same=0 } }; if (same == 1) {print $0}}' file 

here's how works

'{ same=1;                         #assume fields same (i=3;i<nf;i++) {            #for each field after second     if ($i != $2) { same=0 }    #test if field same                                  #the second };  if (same == 1) {print $0}       #if no difference found, print line }' 

Comments

Popular posts from this blog

Magento/PHP - Get phones on all members in a customer group -

php - .htaccess mod_rewrite for dynamic url which has domain names -

Website Login Issue developed in magento -