Get file name which include the current date


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Get file name which include the current date
# 1  
Old 11-05-2012
Get file name which include the current date

Hi,

I'm trying to get the name of a file that has the current date in the name.

The filename is on the form A<current date>01.DC, for example A2012110501.DC


I have this script so far

Code:
date +%y%m%d
D=$(date +%y%m%d)
N=A20$D
echo $N
N2={$N}01.DC
echo $N2

And gets the following output

Quote:
A20121105
}01.DC1105
When I try to add the last part "01.DC" to N something weird happens.

Any ideas on how to get the wanted result?
# 2  
Old 11-05-2012
Code:
D=$(date +'%Y%m%d')

echo "A${D}01.DC"

A2012110501.DC

# 3  
Old 11-05-2012
Code:
~/$ D=$(date +%Y%m%d)
~/$ echo $D    
20121105
~/$  N=A${D}
~/$  echo $N
A20121105
~/$  N2=${N}01.dc
~/$  echo $N2
A2012110501.dc

# 4  
Old 11-05-2012
When add both scripts in a file, test.ksh, I still get the same issue, i.e. get the following output 01.DC1105

However when I run them directly in the terminal I get the wanted result. Sadly I need to be able to use the script in a file (.ksh).

Any suggestions on how to make it work?
# 5  
Old 11-05-2012
Your N2 assignment N2={$N}01.DC is incorrect, try using
Code:
N2=${N}01.DC

BTW, does the %Y(uppercase!) format work with your date version:
Code:
/bin/date +%Y%m%d
20121105

You may want to try it in one go:
Code:
N="A$(date +%Y%m%d)01.DC"; echo $N
A2012110501.DC

# 6  
Old 11-05-2012
Quote:
Originally Posted by RudiC
Your N2 assignment N2={$N}01.DC is incorrect, try using
Code:
N2=${N}01.DC

BTW, does the %Y(uppercase!) format work with your date version:
Code:
/bin/date +%Y%m%d
20121105

%Y works.

However using N2=${N}01.DC still gives me the following result: 01.DC1105

---------- Post updated at 04:58 PM ---------- Previous update was at 04:56 PM ----------

Quote:
Originally Posted by RudiC
[/CODE]You may want to try it in one go:
Code:
N="A$(date +%Y%m%d)01.DC"; echo $N
A2012110501.DC

That worked fine.
Thank you.
# 7  
Old 11-05-2012
This seems like there's a <carriage return> character in N, as it prints A20121105, returns to char #1, and prints 01.DC. Try echo $N|od -tx1 and publish the result here.
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. UNIX for Beginners Questions & Answers

Replace date in file every day with current date

I Have text like XXX_20190908.csv.gz need to replace Only date in this format with current date every day Thanks! (1 Reply)
Discussion started by: yamasani1991
1 Replies

2. UNIX for Beginners Questions & Answers

“sed” replace date in text file with current date

We want to call a parameter file (.txt) where my application read dynamic values when the job is triggered, one of such values are below: abc.txt ------------------ Code: line1 line2 line3 $$EDWS_DATE_INSERT=08-27-2019 line4 $$EDWS_PREV_DATE_INSERT=08-26-2019 I am trying to write a... (3 Replies)
Discussion started by: pradeepp
3 Replies

3. Shell Programming and Scripting

Subtract a file's modification date with current date

SunOS -s 5.10 Generic_147440-04 sun4u sparc SUNW,SPARC-Enterprise Hi, In a folder, there are files. I have a script which reads the current date and subtract the modification date of each file. How do I achieve this? Regards, Joe (2 Replies)
Discussion started by: roshanbi
2 Replies

4. Shell Programming and Scripting

Find big file include current date

Hi, I want to put script. The script is to show file that larger than 100MB include current date (eg: today date). After find the date, it will compress list file and split the tar.gz file. Any idea how to do that? This bash script will run auto everyday. It's will transfer will to other... (12 Replies)
Discussion started by: mzainal
12 Replies

5. UNIX for Dummies Questions & Answers

Delete a row from a file if one column containing a date is greater than the current system date

Hello gurus, I am hoping someone can help me with the required code/script to make this work. I have the following file with records starting at line 4: NETW~US60~000000000013220694~002~~IT~USD~2.24~20110201~99991231~01~01~20101104~... (4 Replies)
Discussion started by: chumsky
4 Replies

6. HP-UX

How do I include header files outside of my current directory

I am trying to compile a file called PPFormatageMUT.c in which I have included header file which are at some other location but the point is that while compiling the file, it is throwing error saying that error : no such file or directory source code location:... (1 Reply)
Discussion started by: ezee
1 Replies

7. Shell Programming and Scripting

Help setting PS1 prompt to include current time

Hi, I'm using the ksh shell and I'd like to set my PS1 prompt on an AIX system to include, amongst ther things, the current time. This was my best effort: export PS1=$(date -u +%R)'${ME}:${PWD}# ' but this only sets the time to the value when PS1 is defined and the time value doesn't... (4 Replies)
Discussion started by: m223464
4 Replies

8. Shell Programming and Scripting

Perl: Extracting date from file name and comparing with current date

I need to extract the date part from the file name (20080221 in this ex) and compare it with the current date and delete it, if it is a past date. $file = exp_ABCD4_T-2584780_upto_20080221.dmp.Z really appreciate any help. thanks mkneni (4 Replies)
Discussion started by: MKNENI
4 Replies

9. Shell Programming and Scripting

File date vs Current date

I am a newbie in shell scripting, hope you can advice how can I compare the date/time of file extracted from 'll' and current system date/time. I have done the following: ll -rt > $FILE_AGE_LOG FILE_DATETIME=`more $FILE_AGE_LOG | head -02 | cut -c 45-57` It returns 'May 4 19:11'. If I... (4 Replies)
Discussion started by: trexlim
4 Replies

10. UNIX for Dummies Questions & Answers

how to give current date in file name?

:) I want to rename a file by giving the actual date as a file name. Is there a command for this? For example file is this: a.txt I want to copy it with a command like this: a20050510.txt (3 Replies)
Discussion started by: simurg11
3 Replies
Login or Register to Ask a Question