To take file based on date passed


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting To take file based on date passed
# 8  
Old 09-21-2017
Why don't you try it and present the resulting code here for analysis?
# 9  
Old 09-21-2017
I have added something like this

Code:
DT=$(date +"%b%y" -d"-1month")

final_file=$(ls  $path/ | grep -i $file$DT | grep .txt )

# 10  
Old 09-21-2017
And - does it come close to something like you want?
# 11  
Old 09-21-2017
Quote:
Originally Posted by RudiC
And - does it come close to something like you want?
Almost but it's searching pattern like filenameaug17. Can you help where is the mistake
# 12  
Old 09-21-2017
No, it doesn't:
Code:
touch filenameaug17.
ls -1 *.txt | while read FN; do [[ "${FN^^}" =~ "${DT^^}" ]] && echo $FN; done
T1_aug17_1.txt
T1_aug17.txt
T1_Aug17.txt

With your approach, try to make the ls command or the regex more specific
# 13  
Old 09-22-2017
Hi,

I didn't get how it will change , because grep $file$DT will search for filenameAug17 pattern.



Code:
DT=$(date +"%b%y" -d"-1month")

final_file=$(ls  $path/ | grep -i $file$DT | grep .txt )

Are you suggesting something like this

Code:
DT=$(date +"%b%y" -d"-1month")

final_file=$(ls  $path/ | grep -i $file| grep | $DT| grep .txt )

Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Calling function, based on agrument passed.

Dears, #!/bin/bash func1() { echo "func1" } func2() { echo "func2" } func3() { echo "func3" } (5 Replies)
Discussion started by: sadique.manzar
5 Replies

2. HP-UX

HP/UX command to pull file name/date based on date

HI, Can anyone tell me how to pull the date and file name separated by a space using the find command or any other command. I want to look through several directories and based on a date timeframe (find -mtime -7), output the file name (without the path) and the date(in format mmddyyyy) to a... (2 Replies)
Discussion started by: lnemitz
2 Replies

3. Shell Programming and Scripting

Subtracting months from passed Date

Hi All, I am getting a date from environment variable and want to do some processing by subtracting 2 months from the date passed through the environment variable. I am trying the following syntax : date_var=2014-08-31 date_2M_ago='$date_var+"%d%m%y" --$date_var="2 months ago" '... (3 Replies)
Discussion started by: Rahul Raj
3 Replies

4. Shell Programming and Scripting

Script to determine Date,TotalFile,total size of file based on date

I have file listed like below -rw-r--r--+ 1 test test 17M Nov 26 14:43 test1.gz -rw-r--r--+ 1 test test 0 Nov 26 14:44 test2.gz -rw-r--r--+ 1 test test 0 Nov 27 10:41 test3.gz -rw-r--r--+ 1 test test 244K Nov 27 10:41 test4.gz -rw-r--r--+ 1 test test 17M Nov 27 10:41 test5.gz I... (5 Replies)
Discussion started by: krish2014
5 Replies

5. Shell Programming and Scripting

How to derive the last Sunday's date when Current date value is passed

Hi All, I have a requirement in my project where a batch runs on any day of a week. The input files will land to the server every Sunday. I need to read these files based on the current BUS_DAY (which falls any day of the week). For e.g : if the BUS_DAY is 20120308, we need to derive the... (3 Replies)
Discussion started by: dsfreddie
3 Replies

6. Programming

create a spool file based on values passed from korn shell to sql script

this is my issue. 4 parameters are passed from korn shell to sql script. parameter_1= varchar2 datatype or no value entered my user. parameter_2= number datatype or no value entered my user. parameter_3= number datatype or no value entered my user. parameter_4= number datatype or no... (5 Replies)
Discussion started by: megha2525
5 Replies

7. Shell Programming and Scripting

Incrementing the date depending on the Counter (parameter) passed to the script

Hello Everyone, I have been trying to complete a shell script where, I need to increment the date depending on the file (depending on the date) availability on the remote server. i.e. Basically, I will be passing a counter (like parameter 1 or 2 or 3 or 4). First I will check for the... (1 Reply)
Discussion started by: filter
1 Replies

8. UNIX for Dummies Questions & Answers

Truncating file based on date

Hi, I need to truncate a file based on date.Suppose i have a log file which is getting updated every date,i need to keep 7 days worth of data(like sysdate-7) and rest i want to truncate it.Can some help me? (5 Replies)
Discussion started by: Param0073
5 Replies

9. Shell Programming and Scripting

Split the file based on date value

Hi frnds, I have flat file as . Say : output-file1.txt Output-file2.txt (1 Reply)
Discussion started by: Gopal_Engg
1 Replies

10. UNIX for Advanced & Expert Users

Delete File Based On Date

Hi Xpert Out There I have a lots of file in this path : -rw-r----- 1 oracle dba 3954176 Dec 21 2006 1_2008.dbf -rw-r----- 1 oracle dba 887808 Dec 21 2006 1_2009.dbf -rw-r----- 1 oracle dba 143872 Dec 21 2006 1_2010.dbf -rw-r----- 1 oracle dba ... (3 Replies)
Discussion started by: adzuanamir
3 Replies
Login or Register to Ask a Question