create separate file after checking condition..

Problem :
I want to create a separate file for country list if condition is true. Please help.


Input file:

SV-INCR-139302-365540488-201104090934.sqllog
SV-INCR-1082-552793184-201104040805.sqllog
SV-INCR-1077-855045741-201104040805.sqllog
SV-INCR-994-386000426-201104080808.sqllog
*****************************************************

Script :

#!/bin/ksh
# with the help of awk command we are taking third value.
awk -F'-' '{print $3}' input|while read third; do
# checking if country code is 139302
if [ $third -eq 139302 ] || [ $third -eq 994 ]; then
   echo $third
fi
   done

output country list file:

SV-INCR-139302-365540488-201104090934.sqllog
SV-INCR-994-386000426-201104080808.sqllog

Is that what you need?

$ awk -F- '$3 == 139302 || $3 == 994' inputfile
SV-INCR-139302-365540488-201104090934.sqllog
SV-INCR-994-386000426-201104080808.sqllog
1 Like

thanks hergp.. command is working file but i want to create two seprate file

  1. one condition is true.
  2. second condition is not true.

---------- Post updated at 02:43 PM ---------- Previous update was at 01:35 PM ----------

i solved my problem.

awk -F- '$3 == 1393awk -F- '$3 == 139302 || $3 == 994' inputfile > conditiontrue
comm -23 inputfile conditiontrue > conditionfalse

awk -F- '$3 == 139302 || $3 == 994{print > "conditiontrue";next}1' inputfile > conditionfalse
1 Like

wow its nice Franklin52