Shell Script if $2 is greater than 10 then echo $1


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Shell Script if $2 is greater than 10 then echo $1
# 1  
Old 04-25-2012
Shell Script if $2 is greater than 10 then echo $1

Hi,

I have a file output.txt

Code:
3258 14
32647 10
32649 10
32650 10
32651 10
32652 10
32653 10
32654 10
32655 10
32656 10
32515 09
32478 08
32555 08
35888 08


I am trying to write a script if $2 i.e. value in column 2 is greater than 10 then if should echo $1 i.e. value of column 1.

Please Help.

Last edited by Scrutinizer; 04-25-2012 at 06:36 AM.. Reason: less than replaced with greater than ( + code tags s.)
# 2  
Old 04-25-2012
Code:
 
awk '$2<10{print $1}' input.txt

# 3  
Old 04-25-2012
My Script is:
Code:
#/bin/bash
T=`date -d '1 hour ago' "+%H"`
echo $T
 
ps -aef|grep httpd|awk ' { print $2 , $5 } ' | cut -d ':' -f1 > /root/output.txt
 
for data in `awk '$2<$T {print $1}' /root/output.txt`
 
do
echo $data - has been killed
#kill $data
echo "--"
done


However it is ignoring condition and echoing all the values on $1.

Last edited by Franklin52; 04-25-2012 at 07:08 AM.. Reason: Please use code tags
# 4  
Old 04-25-2012
change your two lines

1) combine the grep and awk
2) use while loop instead of for loop
Code:
 
ps -aef | awk '/httpd/{ print $2 , $5 } ' | cut -d ':' -f1 > /root/output.txt
awk -v t="$T" '$2<t {print $1}' /root/output.txt | while read data

This User Gave Thanks to itkamaraj For This Post:
# 5  
Old 04-25-2012
use awk with -v option
Code:
 ps -aef|grep httpd|awk ' { print $2 , $5 } ' | cut -d ':' -f1 | awk -vT=`date -d '1 hour ago' "+%H"` ' $2<T {print $1}'

This User Gave Thanks to pravin27 For This Post:
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Shell script to read specified value from file and echo to the same location to other file.

Hello. I want to to backup some "default:" values from a file do some other job and after restore that "default:" values back. The problem is that the source and destination file has a lot of default: strings in it but with different values... So.. Here is an example: A part of my source... (6 Replies)
Discussion started by: ausdim
6 Replies

2. Shell Programming and Scripting

How to echo output of a UNIX command (like ls -l ) using shell script.?

How do i echo the output of a unix command using shell script??? Like: echo /etc/ ls -l (2 Replies)
Discussion started by: sunny2802
2 Replies

3. Shell Programming and Scripting

Script to pull uid greater than 1000 from remote server

Hello, I am trying to get UID # greater than 1000 from all linux server, I tried this script getting this error message, someone please suggest. $for i in `cat hostlist.0709.org` ; do ssh -t $i 'awk -F':' "{ if($3 >= 1000) print $0 }" /etc/passwd ' >> output ; done $ cat output hostname1... (4 Replies)
Discussion started by: bobby320
4 Replies

4. Shell Programming and Scripting

echo prints nothing-shell script

could anyone tell me why when i execute the following script, echo returns blank set k = 1 echo $k (9 Replies)
Discussion started by: saman_glorious
9 Replies

5. Shell Programming and Scripting

shell script, echo doesn't work

#!/bin/sh something(){ echo "Inside something" echo $1 $2 } val=$(something "Hello " "world") Output expected: Inside somethingHello world But it's not echoing. (4 Replies)
Discussion started by: cola
4 Replies

6. Shell Programming and Scripting

shell script to check file size greater than 50M

Hi All, OS:AIX 64 bits using korn shell. Requirement: shell script to check file size greater than 50M and send mail alert. Thanks for your time! Regards, (3 Replies)
Discussion started by: a1_win
3 Replies

7. Shell Programming and Scripting

Shell and echo

Probably my first post, very new to shell scripting :) Here is the script i am trying to modify to use function # Script to create simple menus and take action according to that selected # menu item # while : do clear echo "-------------------------------------" echo "... (2 Replies)
Discussion started by: replyramdas
2 Replies

8. UNIX for Advanced & Expert Users

run a shell script with echo

I need to schedule a shell script that runs at the command prompt to run with crontab. When I run this at the command prompt as follows it works: echo /usr/test/script.sh date1 date2 y | at 20:00 But if I will pass these argument (date1, date2, Y) with in a shell script (say scr1.sh) and... (7 Replies)
Discussion started by: keerthi
7 Replies

9. UNIX for Dummies Questions & Answers

script to autorestart if uptime greater than... help needed.

i'm trying to write a script that will check my os x box for uptime and autorestart gracefully if the uptime is greater than a certain number of days. thus far i have this: if uptime | cut -d ',' -f 1 | cut -d ' ' -f 4 -gt 10 ; then echo "yes" fi this doesn't work and i've tried... (11 Replies)
Discussion started by: alternapop
11 Replies

10. UNIX for Dummies Questions & Answers

echo $SHELL, $PWD and etc.

hi, this echo $SHELL will give the shell name.. how to get the other list of variables (besides SHELL) values? and also, different shells have different variable names (example SHELL) (10 Replies)
Discussion started by: yls177
10 Replies
Login or Register to Ask a Question