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
UNIX command: mv - Objective: move files based on timestamp HLee1981 UNIX for Dummies Questions & Answers 4 07-11-2008 10:02 AM
Find, make and move file based on username Helmi UNIX for Dummies Questions & Answers 5 04-19-2007 06:49 PM
Script for tar and zip based on month & year tuxfello Shell Programming and Scripting 1 09-07-2006 08:52 AM
how to move files into different folders based on filename italia5 UNIX for Dummies Questions & Answers 7 08-23-2006 07:04 AM

Reply
 
LinkBack Thread Tools Display Modes
  #1 (permalink)  
Old 06-11-2008
Registered User
 

Join Date: May 2008
Posts: 8
How do you move lines of numbers based on the month

How do you move lines of numbers i.e.(131, 134, 116, etc...) based on the month? Say for instance I only wanted June numbers and not July. This is what the file looks like so far but it runs everyday in a cron job so it will build to July.

#cat backupcount.log
131 ,Thu Jun 05 08:00:41 2008
134 ,Fri Jun 06 09:41:39 2008
116 ,Sat Jun 07 08:15:24 2008
106 ,Sun Jun 08 08:15:23 2008
95 ,Mon Jun 09 08:15:23 2008
117 ,Tue Jun 10 08:15:42 2008
140 ,Wed Jun 11 08:15:37 2008

I guess my problem is how do you move or copy based on the month. I thought about -mtime in relation to +30 days but some months have 28 and 31 days. How can I differentiate based on the month?
Reply With Quote
Forum Sponsor
  #2 (permalink)  
Old 06-11-2008
Registered User
 

Join Date: Jul 2005
Location: Chicago, IL
Posts: 93
Here's an easy solution:

Code:
grep " Jun " backupcount.log > June.stuff
Then,
Code:
grep -v " Jun " backupcount.log > tmpfile.without.June
mv tmpfile.without.June backupcount.log
BTW, your message was kind of confusing. It seems like you just want to keep your log file cleaned up, and that's what I did. If you're actually trying to move files around, that's another thing entirely.
-mschwage
Reply With Quote
  #3 (permalink)  
Old 06-11-2008
Registered User
 

Join Date: May 2008
Posts: 8
What I am trying to do is calculate all the numbers from the first field at the end of the month for a grand total of the month that just passed. Say for instance all of June on the 1st of July. I know I could just grab those numbers in stick them into excel but I know there is a way to do it on the command line .
Reply With Quote
  #4 (permalink)  
Old 06-11-2008
Registered User
 

Join Date: Mar 2008
Posts: 18
Try this if you want to get every number:

awk '/Jun/ {print $0}' > output.file

or if you want to get the total

awk '/Jun/ {sum+ = $0}
END {print "grand total is:" sum}'
Reply With Quote
  #5 (permalink)  
Old 06-11-2008
Registered User
 

Join Date: Mar 2008
Posts: 18
Sorry the input file was missed

awk '/ / { }' input.file > output.file
Reply With Quote
  #6 (permalink)  
Old 06-13-2008
Registered User
 

Join Date: May 2008
Posts: 8
I can't get the total to work for the file. Is the syntax that is stated exactly how I should put it in.
Reply With Quote
  #7 (permalink)  
Old 06-13-2008
joeyg's Avatar
premier etoile de match
 

Join Date: Dec 2007
Location: Home of world champion Boston Celtics
Posts: 530
Wink another approach to solve

using your same input file

Code:
> cat count_em 
#! /bin/bash
tot_cnt=0
while read zf
  do
  cur_cnt=$(echo "$zf" | grep "Jun" | cut -d"," -f1)
  tot_cnt=$((tot_cnt+cur_cnt))
done <backupcount.log

echo $tot_cnt
Code:
> count_em 
839
Reply With Quote
Google UNIX.COM
Reply

Tags
mtime

Thread Tools
Display Modes




All times are GMT -7. The time now is 02:11 AM.


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

Content Relevant URLs by vBSEO 3.2.0