![]() |
|
|
|
|
|||||||
| Forums | Portal | Register | Forum Rules | FAQ | Contribute | Members List | Arcade | Search | Today's Posts | Mark Forums Read |
| Shell Programming and Scripting Post questions about KSH, CSH, SH, BASH, PERL, PHP, SED, AWK and OTHER shell scripts here. |
|
|
||||
| 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 |
|
|
Submit Tools | LinkBack | Thread Tools | Search this Thread | Display Modes |
|
#1
|
|||
|
|||
|
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? |
| Forum Sponsor | ||
|
|
|
#2
|
|||
|
|||
|
Here's an easy solution:
Code:
grep " Jun " backupcount.log > June.stuff Code:
grep -v " Jun " backupcount.log > tmpfile.without.June mv tmpfile.without.June backupcount.log -mschwage |
|
#3
|
|||
|
|||
|
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 .
|
|
#4
|
|||
|
|||
|
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}' |
|
#5
|
|||
|
|||
|
Sorry the input file was missed
awk '/ / { }' input.file > output.file |
|
#6
|
|||
|
|||
|
I can't get the total to work for the file. Is the syntax that is stated exactly how I should put it in.
|
|
#7
|
||||
|
||||
|
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 |
||||
| Google The UNIX and Linux Forums |
| Tags |
| mtime |
| Thread Tools | Search this Thread |
| Display Modes | |
|
|