linux - How do to multiple grep in if statement bash -


i tried use

if `$(egrep '(cinta|aduh|siapa)' $inputfile)` ;   filter='love' else `$(egrep '(kok|aku|dan)' $inputfile)` ;   filter='jangan' else `$(egrep '(mari)' $inputfile)`;   filter='mari' else `$(egrep '(kerumah|bebeb)' $inputfile)`;   filter='bebeb' else `$(egrep '*' $inputfile)`;   filter='other' fi 

but result

./amosv5: line 175: syntax error near unexpected token `then' ./amosv5: line 175: `  then' 

why getting error.

i need make in php

if (strpos($inputfile, "cinta") || strpos($inputfile, "aduh") || strpos($inputfile, "siapa") { $filter = 'love'; } else { $filter = 'other'; } } 

the syntax plain wrong!

you can use return code of most of shell utilities directly on bash conditionals. here in first condition egrep multiple pattern match cinta|aduh|siapa return true if able find any of patterns. can done rest of parts.

if egrep 'cinta|aduh|siapa' "$inputfile" ;     filter='love' elif egrep 'kok|aku|dan' "$inputfile" ;     filter='jangan' .. 

Comments

Popular posts from this blog

inversion of control - Autofac named registration constructor injection -

verilog - Systemverilog dynamic casting issues -

ios - Change Storyboard View using Seague -