How do you move lines of numbers based on the month


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting How do you move lines of numbers based on the month
# 1  
Old 06-11-2008
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? Smilie
# 2  
Old 06-11-2008
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
# 3  
Old 06-11-2008
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  
Old 06-11-2008
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  
Old 06-11-2008
Sorry the input file was missed

awk '/ / { }' input.file > output.file
# 6  
Old 06-13-2008
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  
Old 06-13-2008
Hammer & Screwdriver 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

Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. UNIX for Dummies Questions & Answers

Need script to move files based on month

Hi , I need a script which moves files based on month. Example : Apr 29 03:16 log4.txt Apr 29 03:16 log5.txt May 4 09:17 log1.txt May 4 09:17 log2.txt Move Apr files into Apr2015(Folder) Move May files into May2015(Folder). This is urgent requirement , if you can help me... (5 Replies)
Discussion started by: rockingvj
5 Replies

2. UNIX for Dummies Questions & Answers

awk - (URGENT!) Print lines sort and move lines if match found

URGENT HELP IS NEEDED!! I am looking to move matching lines (01 - 07) from File1 and 77 tab the matching string from File2, to File3.txt. I am almost done but - Currently, script is not printing lines to File3.txt in order. - Also the matching lines are not moving out of File1.txt ... (1 Reply)
Discussion started by: High-T
1 Replies

3. Shell Programming and Scripting

Fetch files based on month

Hi All I have a requirement like below.I have always 12 files got generated in my directory called /xx/out/ abc_2014_10_121.xml abc_2014_09_345.xml abc_2014_08_432.xml abc_2014_07_123.xml abc_2014_06_098.xml abc_2014_05_569.xml abc_2014_04_430.xml abc_2014_03_235.xml abc_2014_02_056.xml... (9 Replies)
Discussion started by: chigurupati.dwh
9 Replies

4. Shell Programming and Scripting

Last date of month based on parameter

Hi All, How do i get the last date of a month in Unix based on a parameter value. My requirement is if i pass 03/05/2014 as parameter, then i shud get the output/return value as 2/28/2014 If i pass 03/31/2014 as parameter, the output/return value should be 03/31/2014 itself. Also,... (2 Replies)
Discussion started by: galaxy_rocky
2 Replies

5. Shell Programming and Scripting

Extracting lines from text files in folder based on the numbers in another file

Hello, I have a file ff.txt that looks as follows *ABNA.txt 356 24 36 112 *AC24.txt 457 458 321 2 ABNA.txt and AC24.txt are the files in the folder named foo1. Based on the numbers in the ff.txt file, I want to extract the lines from the corresponding files in the foo1 folder and... (2 Replies)
Discussion started by: mohamad
2 Replies

6. UNIX for Dummies Questions & Answers

Extracting lines from a text file based on another text file with line numbers

Hi, I am trying to extract lines from a text file given a text file containing line numbers to be extracted from the first file. How do I go about doing this? Thanks! (1 Reply)
Discussion started by: evelibertine
1 Replies

7. Solaris

Move files into different folders based on its month

Hi All, I want to move the files in to different folders based on the files month in the file timestamp. For example All the september files in the directory should moves into the folder "sep_bkp_files" , August files in to aug_bkp_files folder... Please help me to achive the above... (10 Replies)
Discussion started by: velava
10 Replies

8. Shell Programming and Scripting

Move File Every Last Date of the Month

Dear experts, I have a file named "GI_GR.csv" generated by SAP everyday. What I need is every last date of the month ( Jan 31, Feb 28/29, Mar 31, etc), the file is copied to subfolder named "archive" and rename it to "GI_GR_Jan.csv" for January and so on. What I want to ask is, how to check if... (8 Replies)
Discussion started by: kris.adrianto
8 Replies

9. Shell Programming and Scripting

How to extract log info based on last month?

Hi Gurus I'm using HPUX B.11.23 ia64, the below sample log data was extracted from HPUX commnad: last -R. Sample data: root pts/ta userpc Wed Aug 11 09:46 - 20:21 (10:35) root pts/ta userpc Wed Aug 11 09:44 - 20:10 (10:34) root pts/ta userpc Wed Aug 11... (4 Replies)
Discussion started by: superHonda123
4 Replies

10. Shell Programming and Scripting

How to fetch rows based on line numbers or based on the beginning of a word?

I have a file which will have rows like shown below, ST*820*316054716 RMR*IV*11333331009*PO*40.31 REF*IV*22234441009*xsss471-2762 DTM*003*091016 ENT*000006 RMR*IV*2222234444*PO*239.91 REF*IV*1234445451009*LJhjlkhkj471-2762 </SPAN> DTM*003* 091016 RMR*IV*2223344441009*PO*40.31... (18 Replies)
Discussion started by: Muthuraj K
18 Replies
Login or Register to Ask a Question