dcfargo
1
I'd like to do an if / else if condition and print to different files.
Something like:
awk '{
if ($1 == "yes") print $2, $4 < infile > outfile1 ;
else if ($1 == "No") print $2, $4 < infile > outfile2
}'
Obviously I don't know the syntax.
Thanks so much.
awk '$1=="yes"{print $2, $4 > outfile1} $1=="no"{print $2, $4 > outfile2}' infile
-or-
awk '{if ($1=="yes"){print $2, $4 > "outfile1"}
if($1=="no"){print $2, $4 > "outfile2"}
}' infile
-or-
awk '{p=($1=="yes")?1:2; print $2, $4 > "outfile"p}' infile
Scott
3
awk '
$1 == "yes" { print $2, $4 > "outfile1" }
$1 == "no" { print $2, $4 > "outfile2" }
' infile
dcfargo
4
Thanks so much. That worked.
ichigo
5
gawk '$1~/^(yes|no)$/{ print $2,$4 > "outfile."$1}' inputfile
Scott
6
No-where in the OP's question did I see where the output files should be called output.yes or output.no...
I don't have gawk, and your code doesn't work with awk.