LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - Newbie (http://www.linuxquestions.org/questions/linux-newbie-8/)
-   -   compare second column of a file then print the first column of it in a ne fil if true (http://www.linuxquestions.org/questions/linux-newbie-8/compare-second-column-of-a-file-then-print-the-first-column-of-it-in-a-ne-fil-if-true-934659/)

java_girl 03-15-2012 05:06 PM

compare second column of a file then print the first column of it in a ne fil if true
 
I have this input in my file.txt

213.236.6.230 58 1435
213.236.6.249 24 1532
213.236.9.58 19 67
213.236.10.80 9 1226
213.236.9.193 3 203

I need to compare if 58 > 10, if it is i will save 213.236.6.230 in file2.txt if not go to the next line and so on. Please help.

danielbmartin 03-15-2012 05:25 PM

Quote:

Originally Posted by java_girl (Post 4627810)
I have this input in my file.txt

213.236.6.230 58 1435
213.236.6.249 24 1532
213.236.9.58 19 67
213.236.10.80 9 1226
213.236.9.193 3 203

I need to compare if 58 > 10, if it is i will save 213.236.6.230 in file2.txt if not go to the next line and so on. Please help.

Try this...
Code:

awk '{if ($2 > 10) {print $1}}' $InFile > $OutFile
Daniel B. Martin

grail 03-16-2012 04:50 AM

You can also bypass the "if" as anything outside a pair of {} will be evaluated:
Code:

awk '$2 > 10{print $1}' file > outfile


All times are GMT -5. The time now is 12:23 PM.