How to rename file name?


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting How to rename file name?
# 1  
Old 02-22-2016
How to rename file name?

Hi ,

Please help me am new in shell script how to rename file name as per previouse year

Code:
 
date | cut -c 27-28
mv file XYP.ZAT15.PGPNX.TRDIY

output should display

renamed as
Code:
XYP.ZAT15.PGPNX.TRDIY


The file name should be renamed as XYP.ZAT15.PGPNX.TRDIY 15 is the previous year, so year should be add second filed mentioned as bold letter
# 2  
Old 02-22-2016
The solution depends highly on the OS, shell, and date versions that you have. With GNU date, you can try
Code:
mv file XYP.ZAT$(date -d-365day +%y).PGPNX.TRDIY

# 3  
Old 02-22-2016
i am using korn shell and Aix operating system it is not working
# 4  
Old 02-22-2016
Hello jagu,

Could you please try following and let me know if this helps you(Not test though).
Code:
mv Input_file  XYP.ZAT$(date | awk '{print $NF-1}').PGPNX.TRDIY

Thanks,
R. Singh
# 5  
Old 02-22-2016
Hi Ravi
working display XYP.ZAT2015.PGPNX.TRDIY but i need add 2 digit prevoius year only
XYP.ZAT15.PGPNX.TRDIY plz


---------- Post updated at 08:11 AM ---------- Previous update was at 08:04 AM ----------

Thanks rudic and ravi

It is working
Code:
 
 mv file XYP.ZAT$(date | cut -c 27-28).PGPNX.TRDIY
but it display current year XYP.ZAT16.PGPNX.TRDIY

if u have awk code plz share
# 6  
Old 02-22-2016
Hello jagu,

Following may help you in same then(Not tested though).
Code:
mv Input_file  XYP.ZAT$(date | awk '{num=split($NF-1, A,"");print A[num-1] A[num]}').PGPNX.TRDIY

Thanks,
R. Singh
This User Gave Thanks to RavinderSingh13 For This Post:
# 7  
Old 02-22-2016
it dispay same result

Code:
 
XYP.ZAT2015.PGPNX.TRDIY

not display 2 digit year 'yy' numbers

---------- Post updated at 08:40 AM ---------- Previous update was at 08:22 AM ----------

thanks it works

mv file XYP.ZAT$(date | awk '{print $NF-1}'| cut -c 3-4).PGPNX.TRDIY

Last edited by jagu; 02-22-2016 at 09:28 AM..
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Bash to copy file 3 times and rename based on another file

In the below bash I am trying to copy the only text file (always only one) in /home/cmccabe/Desktop/list/QC/metrics.txt and rename each of the 3 text files according to /home/cmccabe/Desktop/test/list.txt using lines 3, 4 ,5. This format (that is list.txt) is always 5 lines. Thank you :). ... (12 Replies)
Discussion started by: cmccabe
12 Replies

2. Shell Programming and Scripting

Rename specific file extension in directory with match to another file in bash

I have a specific set (all ending with .bam) of downloaded files in a directory /home/cmccabe/Desktop/NGS/API/2-15-2016. What I am trying to do is use a match to $2 in name to rename the downloaded files. To make things a more involved the date of the folder is unique and in the header of name... (1 Reply)
Discussion started by: cmccabe
1 Replies

3. UNIX for Dummies Questions & Answers

awk - Rename output file, after processing, same as input file

I have one input file ABC.txt and one output DEF.txt. After the ABC is processed and created output, I want to rename ABC.txt to ABC.orig and DEF to ABC.txt. Currently when I am doing this, it does not process the input file as it cannot read and write to the same file. How can I achieve this? ... (12 Replies)
Discussion started by: High-T
12 Replies

4. UNIX for Dummies Questions & Answers

look for specific values in a file and rename file with value found

Hi, i have a file with some data ..look for some specific value in the file and if found that value rename the file with the value found in the file.. ex.. File.txt 1236 43715825601ANDERSSON, 1236 437158256031963040120060901200609010000000 1236 43715825604123 MCCL AVE UPPER 1236 ... (11 Replies)
Discussion started by: dssyadav
11 Replies

5. UNIX for Dummies Questions & Answers

Rename a file

how to rename a file if I don't know file location ? Can we below command : $ find / | mv file1.txt I am not sure........can any1 help me out ? Thanks, Tushar Joshi:mad: (1 Reply)
Discussion started by: tusharjoshi
1 Replies

6. Shell Programming and Scripting

[ask]rename file

dear all, i have case with this: i have file 20110601.txt so i want to auto rename this file like this 20110601_20110602.txt actual this rename will create if 20110601 came in date 20110602(date from system unix) so this will be using #!/bin/bash folder='/home' desti='/home/desti'... (2 Replies)
Discussion started by: zvtral
2 Replies

7. Shell Programming and Scripting

A script that will move a file to a directory with the same name and then rename that file

Hello all. I am new to this forum (and somewhat new to UNIX / LINUX - I started using ubuntu 1 year ago).:b: I have the following problem that I have not been able to figure out how to take care of and I was wondering if anyone could help me out.:confused: I have all of my music stored in... (7 Replies)
Discussion started by: marcozd
7 Replies

8. UNIX for Dummies Questions & Answers

Rename file based on first 3 characters of data in file

I'm looking to determine if I can use a grep command to read file and rename the file based on the first 3 characters of the data in the file. An example is: Read FileA If the first 3 positions of the data in the file are "ITP", then rename the file as FileA_ITP, else if the first 3... (3 Replies)
Discussion started by: jchappel
3 Replies

9. Shell Programming and Scripting

Rename a file name

Hi, I am getting a file name from a remote server thru ftp and storing this filename in a variable. I am doing this in ftp mode. for ex: the filename is like emp_010208. This file name has to be changed to emp. Can you please let me know how we can do this while we are in ftp mode. thanks,... (0 Replies)
Discussion started by: Aswarth
0 Replies

10. UNIX for Dummies Questions & Answers

Help with multiple file rename - change case of part of file name

Hi there, I hope someone can help me with this problem : I have a directory (/var/www/file/imgprofil) which contains about 10000 JPG files. They have a naming convention thus : prefix-date-key-suffix.jpg they all have the prefix p-20050608- then AAAA is a 4 letter code the suffix is... (7 Replies)
Discussion started by: steve7
7 Replies
Login or Register to Ask a Question