this question has answer here:
i'm trying use process substitution grep follows:
#!/bin/bash if [grep -c "*" <(cut -d"," -f5 input_q1.csv) ] echo "yes"; else echo "no"; fi
but i'm getting error:
line 2: [grep: command not found
what missing?
[ ... ]
not part of syntax of if-statement; rather, [
(also called test
) bash built-in command commonly used test-command in if-statement.
in case, test-command grep
rather [
, write:
if grep -c "*" <(cut -d"," -f5 input_q1.csv) ;
additionally, there's no real reason use process substitution here. overall result of pipeline result of final command in pipeline; , grep supports reading standard input. can write:
if cut -d"," -f5 input_q1.csv | grep -c "*" ;
to support wider range of systems.
(incidentally, quotation marks around ,
don't anything: -d","
means -d,
means "-d,"
. if goal "highlight" delimiter, or set off in way, might make more sense split separate argument: -d ,
. that's matter of preference.)
Comments
Post a Comment