Sponsored Content
Top Forums Shell Programming and Scripting Shell program question with Filenames and dates Post 303014713 by SK123 on Monday 19th of March 2018 12:58:22 PM
Old 03-19-2018
Shell program question with Filenames and dates

Hi Unix Gurus

Let's say I have the input files like the following. I need to pick the files based on my run date.

Code:
abcd_20180206.csv
abcd_20180213.csv
abcd_20180220.csv
abcd_20180227.csv
efgh_20180206.csv
efgh_20180220.csv
efgh_20180227.csv
ijkl_20180206.csv
ijkl_20180213.csv
ijkl_20180220.csv
ijkl_20180227.csv
mnop_20180206.csv
mnop_20180213.csv
mnop_20180220.csv
mnop_20180221.csv
mnop_20180227.csv
qrst_20180206.csv
qrst_20180213.csv
qrst_20180220.csv
qrst_20180227.csv
uvwx_20180206.csv
uvwx_20180213.csv
uvwx_20180220.csv
uvwx_20180227.csv
yyzz_20170606.csv

So if I am running for 20180206 or 20180209 or 20180212, The output of the above should be:

Code:
abcd_20180206.csv
efgh_20180206.csv
ijkl_20180206.csv
mnop_20180206.csv
qrst_20180206.csv
uvwx_20180206.csv
yyzz_20170606.csv

And if I am running for 20180213 or 20180215 or 2018019, The output of the above should be:

Code:
abcd_20180213.csv
efgh_20180206.csv
ijkl_20180213.csv
mnop_20180213.csv
qrst_20180213.csv
uvwx_20180213.csv
yyzz_20170606.csv

Also if I am running for 20180221, The output of the above should be:

Code:
abcd_20180220.csv
efgh_20180221.csv
ijkl_20180220.csv
mnop_20180220.csv
qrst_20180220.csv
uvwx_20180220.csv
yyzz_20170606.csv

Can someone please help me with this?

Thanks & regards,
SK


Moderator's Comments:
Mod Comment Please use CODE tags as required by forum rules!

Last edited by RudiC; 03-19-2018 at 02:21 PM.. Reason: Added CODE tags.
 

10 More Discussions You Might Find Interesting

1. UNIX for Dummies Questions & Answers

reading filenames inside a program

UNIX Sun Ultra60 5.5.1 Hello everybody, I have a problem that seems simple but turns out to be complex (for me at least). My program needs to open a directory (this part is easy), scan each filename and determine whether or not a file with the suffix (.07) exists. So the program would return... (5 Replies)
Discussion started by: j_t_kim
5 Replies

2. UNIX for Dummies Questions & Answers

While we are on the subject of dates. Another date question

This goes deeper into the date thing. I want to be able to check the date and time stamp in or on a file to see what the time span is. We have a job that runs several times an hour - kicked off through cron based on a trigger file. We want to keep track of each run and check the time between... (14 Replies)
Discussion started by: MizzGail
14 Replies

3. Shell Programming and Scripting

Awk question: Sum dates

Hi there, I have a logfile which has the following layout: 20080812 0 20 20080812 12 10 20080812 12 10 20080812 12 10 I want to sum the "12" on the last 3 lines and save the "20" on the first line. The final output should be 20080812 36 20 I think that should me more easier with... (6 Replies)
Discussion started by: BufferExploder
6 Replies

4. Shell Programming and Scripting

Question on reading dates in folders/files

Hi All, I have some folder that are named "FOLDERYYYYMM". I'm trying to piece together a .sh script that will look for the folder with the date. How can I get shell to see the date? (3 Replies)
Discussion started by: bbbngowc
3 Replies

5. UNIX for Dummies Questions & Answers

Question/review my script: removing bad chars from filenames

The task: remove undesirable characters from filenames. Restrictions: Must use basic RE, base utilities (non-GNU) and /bin/sh (ash). No ksh, zsh, perl, etc. Below is what I've come up with. It seems to work OK but I'm open to shorter, more efficient alternatives. Inside the square... (4 Replies)
Discussion started by: uiop44
4 Replies

6. Shell Programming and Scripting

Spaces in filenames located in variables in shell.

Greetings. I am trying to do a script that will do some file copying for me. Unfortunately I have spaces in the directory names (which I cannot change) and the result is someone hard to achieve in shell scripts. I have searched everywhere on the web but does not manage to find the answer to... (3 Replies)
Discussion started by: Mr.Glaurung
3 Replies

7. Shell Programming and Scripting

Filenames in CSH shell

Hi, I am running into a bit of a problem. I am trying to write a script that will run an interactive (fortran) program repeatedly to dump data across 36 data channels... anyway. I have gotten this far... #!/bin/csh set i=0 while ($i<2) fitsfilter $1<<EOF $i 0 9 1 1 g 2 1250 -100... (5 Replies)
Discussion started by: madtowneast
5 Replies

8. Shell Programming and Scripting

Awk program for calculating dates.

Hi All, I have a txt file which has hundreds of lines and 41 fields. I have a requirement to pick up field 14 from the text file which is a date fiels in the following format. Field 14 : Data Type : NUMERIC DATE (YYYYMMDD) Field Length : 8 Example of Data :20090415 Field 42 : Data Type... (2 Replies)
Discussion started by: nua7
2 Replies

9. Shell Programming and Scripting

Storing filenames in an array in shell script

hi, i am writing a shell script in which i read a line in a variable. FNAME="s1.txt s2.txt s3.txt s4.txt s5.txt" i want to create a array and store single file names in a array.. so the array should contain arr="s1.txt" arr="s2.txt" arr="s3.txt" arr="s4.txt" arr="s5.txt" how to... (3 Replies)
Discussion started by: Little
3 Replies

10. Shell Programming and Scripting

Help on Dates in Shell Scripting

Hi Experts, I am using the below code to get the previous day based on the date given as a input. #!/usr/bin/ksh datestamp=`date '+%Y%m%d'` yest=$((datestamp -1)) echo $yest Output: 20130714 How can i display the same output in 14/07/2013, i tired '+%d/%m/%y'` but i am getting... (16 Replies)
Discussion started by: learner24
16 Replies
All times are GMT -4. The time now is 02:59 PM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy