Create file with last month in filename


 
Thread Tools Search this Thread
Top Forums UNIX for Dummies Questions & Answers Create file with last month in filename
# 1  
Old 02-27-2013
Create file with last month in filename

Hi,

I have a bash script which outputs a file with current year and month in the filename.
Last line is:
Code:
cat result_* > output.$(date +%y%m)

So for Feb 2013 this gives me output.1302

Now I am requested to run the script every first day of the month, but with the previous month in the filename.
Running the script on March 1st 2013 should not return output.1303, but should return output.1302.

Is there a way of setting that?

Many thanks,
Viscacha
# 2  
Old 02-27-2013
Try this

Code:
cat result_* > output.$(date -d "-1days" +%y%m)

# 3  
Old 02-27-2013
If it is running reliably and consistently on the month's first, and if you have GNU date, try
Code:
$ date -dyesterday +%y%m

# 4  
Old 02-27-2013
If previous solutions don't work...
Code:
cat result_* > output.$(date +"%y %m"| awk '{print ($2==1)?($1-1)*100+12:($1)*100+$2-1}')

# 5  
Old 03-04-2013
Thanks everyone.
 
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Create 2 Columns from filename

Hi, I have a directory of files with filenames all in the format of xxx_yyy_zzz.pdf Where xxx and yyy changes each filename but zzz stays the same. For example: File 1: Gold_Car_Vehicle.pdf; File n: Red_Truck_Vehicle.pdf. I need to cycle through each file and output a Text File with 2 columns.... (2 Replies)
Discussion started by: ndnkyd
2 Replies

2. UNIX for Dummies Questions & Answers

How to create a cronjob for the 3rd business day of every month?

Hello, Can you please help me out in creating a cronjob that runs every 3rd business day of the month. Thanks (2 Replies)
Discussion started by: AReddy
2 Replies

3. Shell Programming and Scripting

Adding Previous Month To Filename

Dear experts, I'm using solaris 5.10 and bash. I want to zip file "Amount.txt" to "Amount.zip" and rename it to "Amount_<prev_month>_<this year>.zip". For example, file for this month should be renamed to "Amount_06_2012.zip", for next month it should be "Amount_07_2012.zip". I have no problem... (8 Replies)
Discussion started by: kris.adrianto
8 Replies

4. Shell Programming and Scripting

Merge CSV files and create a column with the filename from the original file

Hello everyone!! I am not completely new to shell script but I havent been able to find the answer to my problem and I'm sure there are some smart brains here up for the challenge :D. I have several CSV files that I need to combine into one, but I also need to know where each row came from.... (7 Replies)
Discussion started by: fransanchezoria
7 Replies

5. Shell Programming and Scripting

create new column for filename

Hi, I created a list with 2 columns. Each line is from a different file. I am getting these with a loop in Perl. I would like to add a 3rd column with the name of the file that the line is coming from. I usually use pr to print the filename but this is not working here ... I was wondering if... (5 Replies)
Discussion started by: danieladna
5 Replies

6. Shell Programming and Scripting

Extract date from filename and create a new file

Hi, i have a filename CRED20102009.txt in a server 20102009 is the date of the file ddmmaaaa format the complete route is /dprod/informatica/Fuentes/CRED20102009.csv i want to extract the date to create a new file named Parameters.txt I need to create Parameters.txt with this... (6 Replies)
Discussion started by: angel1001
6 Replies

7. Shell Programming and Scripting

How to find the create time of a file if current date is in next month

Hi All, I want to find the time diffrence between currnt time and "abc.txt" file create time. I have solve that but if the abc.txt file created last month then is there any process to find the difftent? Exp: Create time of abc.txt is "Apr 14 06:48" and currect date is "May 17 23:47".... (1 Reply)
Discussion started by: priyankak
1 Replies

8. Shell Programming and Scripting

read mp3 filename and create one XML for each file

Hi: I have a collection of mp3s and I need to create 1 xml file per mp3. I have: recording1.mp3 recording2.mp3 etc and I want to generate this kind of files. recording1.xml recording2.xml and inside each xml file I need to add a url prefix and then the filename at the end. ... (4 Replies)
Discussion started by: jason7
4 Replies

9. Shell Programming and Scripting

create filename with 'DD/MM/YYYY' date format

Hi, I can use the following command to create a file with some name then underscore and then date appended to it in the format 'DD-MM-YYYY': touch "newfile_`date '+%d-%m-%Y'`" But it gives me error when I try with the similar command to create a file with the date format 'DD/MM/YYYY'. I... (4 Replies)
Discussion started by: royalibrahim
4 Replies

10. UNIX for Dummies Questions & Answers

Delete filename with month -2

KSH - I've got a script that is generating a number of log files like this: y=`date +"%y"` m=`date +"%m"` $LOG_DIR/tuscprof_tbl_$y$m.log I only want to keep the current 2 months' worth of files (current month and prior month). So I'm trying to come up with a way to delete any that... (1 Reply)
Discussion started by: dstinsman
1 Replies
Login or Register to Ask a Question