The UNIX and Linux Forums  

Go Back   The UNIX and Linux Forums > Top Forums > Shell Programming and Scripting
Google UNIX.COM


Shell Programming and Scripting Post questions about KSH, CSH, SH, BASH, PERL, PHP, SED, AWK and OTHER shell scripts here.

More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
Problem in For Loop The Observer Shell Programming and Scripting 2 05-27-2008 11:43 PM
for loop problem namishtiwari Shell Programming and Scripting 5 01-25-2008 09:58 AM
loop problem maskot Shell Programming and Scripting 1 05-25-2007 01:10 AM
Problem with for loop/sed ? chiru_h Shell Programming and Scripting 2 08-27-2006 08:55 AM
problem with while loop mridula High Level Programming 1 12-11-2005 08:44 AM

Reply
 
Submit Tools LinkBack Thread Tools Search this Thread Display Modes
  #1  
Old 02-04-2008
Registered User
 

Join Date: Dec 2007
Location: Philippines, Cebu City
Posts: 67
awk and loop problem

Good morning,
Sir's i would like to ask for help regarding to my awk and loop problem, a script that will check my files a and b then if it will see there was a time below 3am it will echo the file that contains below 3am file, for this example it will redirect the file a to an output.
$ cat a
Sun Feb 3 08:49:01 EAT 2008
Sun Feb 3 12:09:33 EAT 2008
Mon Feb 4 01:44:48 EAT 2008
Mon Feb 4 13:02:00 EAT 2008

$cat b
Sat Feb 2 08:14:34 EAT 2008
Sat Feb 2 09:55:36 EAT 2008
Sun Feb 3 08:44:13 EAT 2008
Sun Feb 3 09:46:38 EAT 2008
Mon Feb 4 07:43:09 EAT 2008
Mon Feb 4 09:41:24 EAT 2008

desired output:
file a has below 3 am.

Thanks
Reply With Quote
Forum Sponsor
  #2  
Old 02-04-2008
Ygor's Avatar
Moderator
 

Join Date: Oct 2003
Location: -31.96,115.84
Posts: 1,249
Try...
Code:
awk -F '[ :]' '$4+0<n{printf "File %s below %s\n", FILENAME, n}' n=3 a b
Reply With Quote
  #3  
Old 02-04-2008
blowtorch's Avatar
Supporter
 
Join Date: Dec 2004
Location: Singapore
Posts: 2,328
Do you have to use awk here? This will work too:

Code:
while read one two three four rest; do 
   if [ ${four%%:*} -lt 3 ]; then 
      echo file a has below 3 am; 
      break; 
   fi; 
done < a
while read one two three four rest; do 
   if [ ${four%%:*} -lt 3 ]; then 
      echo file b has below 3 am; 
      break; 
   fi; 
done < b
If you have a lot of files, you can loop for each file too.
Reply With Quote
  #4  
Old 02-04-2008
Registered User
 

Join Date: Dec 2007
Location: Philippines, Cebu City
Posts: 67
great! thanks to all
Reply With Quote
Google The UNIX and Linux Forums
Reply

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes




All times are GMT -7. The time now is 06:44 AM.


Powered by: vBulletin, Copyright ©2000 - 2006, Jelsoft Enterprises Limited.
The UNIX and Linux Forums Content Copyright ©1993-2008. All Rights Reserved.Ad Management by RedTyger Visit The Complex Event Processing Blog

Content Relevant URLs by vBSEO 3.2.0