Today (Saturday) We will make some minor tuning adjustments to MySQL.

You may experience 2 up to 10 seconds "glitch time" when we restart MySQL. We expect to make these adjustments around 1AM Eastern Daylight Saving Time (EDT) US.

Read file name based on date

Login or Register to Reply

Thread Tools Search this Thread
# 1  
Read file name based on date


I have file name as Example

I have to read file name based on date(i.e) files with same date and copy to another directory in shell script.


Last edited by rbatte1; 08-18-2016 at 07:18 AM.. Reason: Added CODE tags for file name list
# 2  
Hello caba_jones ,

I have a few to questions pose in response first:-
  • What have you tried so far?
  • What output/errors do you get?
  • What OS and version are you using?
Most importantly, What have you tried so far?

There are probably many ways to achieve most tasks, so giving us an idea of your style and thoughts will help us guide you to an answer most suitable to you so you can adjust it to suit your needs in future.

We're all here to learn and getting the relevant information will help us all.

Kind regards,
# 3  
i tried to extract the date using the below code but not able to,can you please check
#Script for copying files from src to dest based on same date and time

#Script Variables
ACTION_TIME=`date +'%Y%m%d' "%H:%M:%S:"`

echo "${ACTION_TIME} Starting copy task" 
find ${SPATH} -type f -name "${SUFFIX_ARG}" -print | while read path
   FN="${path##*/}" #extract the file name from the path
  date=${temp%.txt.pgp} # trying to get the date alone 
   echo "this is the file name"$FN 
   ACTION_TIME=`date +"%Y%m%d %T"`
     if [ -e "${DPATH}/${FN}" ]   #if the destination file exists, skip it
      echo "${ACTION_TIME} Skipped: File ${DPATH}/${FN} already exist"  
	   cp "$path" "${DPATH}/${FN} ${ACTION_TIME}"  
	   ACTION_TIME=`date +"['%y%m%d' %T]:"`
	   echo "${ACTION_TIME} Copy ${FN} to ${DPATH} Complete"  
   echo "done copy"

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

Last edited by RudiC; 08-18-2016 at 12:28 PM.. Reason: Added/corrected CODE tags.
# 4  
Some comments (not necessarily in severity order or order of appearance):
- consider refraining from using variables named close to PATH (essential system variable for your session; used to locate commands!) so you don't mess up your session by accident.
- your first ACTION_TIME assignment has a syntax error in the date command.
- giving variables (date) identical names to commands may lead to confusion.
- what do you create the date variable for in the first place?
- consider using the recommended $(...) notation in lieu of the deprecated `...` for "command substitution".
- your find command won't find any of the files quoted in post#1 as the pattern in SUFFIX_ARG doesn't match.
- the test for existence is for a different file than the one actually copied, so probably pointless.

On top, the specification in post#1 is sparse by itself, and it is not improved by your second post. Why don't you take a step back, start over, and present your problem in a decent, precise, detailed way supported by samples?

Last edited by RudiC; 08-18-2016 at 01:43 PM..
Login or Register to Reply

Thread Tools Search this Thread
Search this Thread:
Advanced Search

More UNIX and Linux Forum Topics You Might Find Helpful
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...... HP-UX
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...... Shell Programming and Scripting
Shell Programming and Scripting
Help with ksh-to read ip file & append lines to another file based on pattern match
Hi, I need help with this- input.txt : L B white X Y white A B brown M Y black Read this input file and if 3rd column is "white", then add specific lines to another file insert.txt. If 3rd column is brown, add different set of lines to insert.txt, and so on. For example, the given...... Shell Programming and Scripting
Shell Programming and Scripting
Read a date value from other file.
My Situation is I have to read a date value from previuosly created file and need to increment the date in the newly created file. I need unix scripting for the above condtion. Thanx in advance.... Shell Programming and Scripting
Shell Programming and Scripting
Read file based on condition
Hi Friends, Can any one help with this: I have a huge file with the format as A SAM 4637 B DEPT1 4758 MILAN A SMITH 46585 B DEPT2 5385 HARRYIS B SAMUL 63547 GEORGE B DANIEL 899 BOISE A FRES 736 74638 I have to read this file and write only the records that starts with "B" only ...... Shell Programming and Scripting
Shell Programming and Scripting

Featured Tech Videos