Appending date to UNIX Filenames


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Appending date to UNIX Filenames
# 1  
Old 07-22-2013
Appending date to UNIX Filenames

Hello,

I have a file name in the below format and have to append the date as _$currdate.

kchik_UK_lo.txt_$currdate.

The above should be the format and I dont want to put entire filename as above in the code, but it should give me the output as the above filename.Can anyone please help me out.

Thanks for all the help in advance
# 2  
Old 07-22-2013
Code:
mv kchik_UK_lo.txt kchik_UK_lo.txt_$(date +%Y%m%d)

# 3  
Old 07-22-2013
Thank you..
I dont want to put entire filename in the script(for ex: kchik* )how can I give the above filename using wildcard characters like *.please help.
# 4  
Old 07-22-2013
Quote:
Originally Posted by harika03
Thank you..
I dont want to put entire filename in the script(for ex: kchik* )how can I give the above filename using wildcard characters like *.please help.
Code:
for file in kchik*
do
        mv "$file" "${file}_$(date +%Y%m%d)"
done

# 5  
Old 07-22-2013
Thanks a lot..Smilie

---------- Post updated 07-22-13 at 01:06 AM ---------- Previous update was 07-21-13 at 11:52 PM ----------

One last help how can I send these filenames(only name of the files) in an email..?
# 6  
Old 07-22-2013
Check mailx manual page or search this forum.
# 7  
Old 07-22-2013
Instead of for loop can we use any other way for modiffying the filename
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. UNIX for Dummies Questions & Answers

Searching by date range from filenames

Hello all, i have tons of files in folder named like this (yyyymmdd): bookcollection20100729 bookcollection20100730 bookcollection20100731 bookcollection20100801 bookcollection20100802 etc. I need to find files with date range in there names lets say from 2010.07.30 - 2010.08.02 ... (10 Replies)
Discussion started by: Whit3H0rse
10 Replies

2. UNIX Desktop Questions & Answers

Appending file extensions to filenames in bash scripts

Hi Suppose I have a variable called filename and it it contains the name of a file. I then would like to append an extension to that filename. The filename currently has no extensions. How do I do this? Thanks (11 Replies)
Discussion started by: ladyAnne
11 Replies

3. Shell Programming and Scripting

How to extract date out of this filenames

I have filenames filenameA_fg_MMDDYY.tar.gz filenameASPQ_fg_MMDDYY.tar.gz filenameAFTOPHYYINGH_fg_MMDDYY.tar.gz filenameAGHYSW_fg_MMDDYY.tar.gz Is there a way I can extract the date out of these filenames? Thanks in advance (2 Replies)
Discussion started by: RubinPat
2 Replies

4. UNIX for Dummies Questions & Answers

issue on reading the file and appending date

Hi Am having issue on appending time stamp I know the exact file names in the directory like a.dat b.dat c.dat e.dat f.dat I want to read all these file names and append the timestamp to each files like a.dat.20090604,b.dat.20090604 and move to the different directory. ... (3 Replies)
Discussion started by: bobprabhu
3 Replies

5. Shell Programming and Scripting

appending date at the end of the file

I have file called xx Now i want to rename this file as xxYYYYMMDD_HHMIAM.xls Here is my code.. export DATE1=`date +%Y%m%d` mv xx xx$DATE1 This code renames as xxYYYYMMDD Now how can i append HHMIAM at the end of the file? Any help is appreciated... (3 Replies)
Discussion started by: govindts
3 Replies

6. UNIX for Dummies Questions & Answers

extracting and using date from filenames in a loop

HIya, Having a dumb day whilst writing an archive process in Shell want to extract from the filename the date and archive into tar files based on this, I don't want to use mtime as it may not be the actual file date. The files are -rw-rw---- 1 user admin 100 Aug 29 11:10... (2 Replies)
Discussion started by: badg3r
2 Replies

7. Shell Programming and Scripting

Appending date

hi All, Searched forum but couldn't find a solution to this problem: How can I append a file with date in the ninth line? ie I want to insert a line with the current date and time in the ninth line. I tried this: date=`date` awk 'NR==9 {printf "'$date' \n"} {print $0}' abc.log below... (10 Replies)
Discussion started by: Sreejith_VK
10 Replies

8. Shell Programming and Scripting

Appending date to filename

hi i need to rename a.txt to a_12052008.txt using the batch file i used reanme a.txt a_%date%.txt ......but its done nothing am using win2000 professional edition. system date format is : The current date is: Mon 2008-05-12 can anyone help me to rename thanks aemu (5 Replies)
Discussion started by: aemunathan
5 Replies

9. Shell Programming and Scripting

Date Not appending in log file

Hi experts . . . Sunsolaris 9 version I have the script as below: Am getting log file as : archive_today_.log Please suggest. ################################################## set 'date' dd=$3 mon=$2 export mon yyyy=$6 export yyyy cd /oracle/P47/saparch (4 Replies)
Discussion started by: vrjalli
4 Replies

10. UNIX for Dummies Questions & Answers

Appending text to a number of similar filenames

Hi, I was wondering if there was a way to append something to filenames based on a wildcard. For example, if I have the following files in a directory: blah1 blah2 blah3 blah4 blah5 I want to rename these all to: blah1.txt blah2.txt blah3.txt blah4.txt blah5.txt Is there a... (4 Replies)
Discussion started by: Djaunl
4 Replies
Login or Register to Ask a Question