renaming part of a file


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting renaming part of a file
# 1  
Old 04-23-2006
renaming part of a file

I have file like this


xxxx_yyyy.sh
tttt_yyyy.sh
aaaa_yyyy.sh

how can I do that ?

please help me

thanks
# 2  
Old 04-23-2006
Sorry I missed what I wanted to do
I Like to rename as

leave the portion before the _ and only change after _

like aaaa_zzzz.sh
tttt_zzzz.sh

etc

thanks
# 3  
Old 04-23-2006
Code:
$ ls *.sh
aaaa_yyyy.sh  tttt_yyyy.sh  xxxx_yyyy.sh
$ echo $0
/bin/bash
$ for file in *.sh; do mv ${file} ${file%%_*}_zzzz.sh; done
$ ls *.sh
aaaa_zzzz.sh  tttt_zzzz.sh  xxxx_zzzz.sh

or...
Code:
$ ls *.sh
aaaa_yyyy.sh  tttt_yyyy.sh  xxxx_yyyy.sh
$ for file in *.sh; do mv ${file} `echo ${file} | sed 's/\([^_]*_\)[^.]*\(\.sh\)/\1zzzz\2/'`; done
$ ls *.sh
aaaa_zzzz.sh  tttt_zzzz.sh  xxxx_zzzz.sh

Many ways to do this....

Cheers
ZB
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. UNIX for Beginners Questions & Answers

How to make a loop to read the input from a file part by part?

Hi All, We've a VDI infrastructure in AWS (AWS workspaces) and we're planning to automate the process of provisioning workspaces. Instead of going to GUI console, and launching workspaces by selecting individual users is little time consuming. Thus, I want to create them in bunches from AWS CLI... (6 Replies)
Discussion started by: arun_adm
6 Replies

2. Windows & DOS: Issues & Discussions

Renaming part of a text file ?

I have several files that are named like this "DotP_D14 - Verknüpfung" They all have the " - Verknüpfung" in common. I'd like to rename all of them to get rid of that last part. Is this possible with DOS on windows ? (1 Reply)
Discussion started by: pasc
1 Replies

3. UNIX for Dummies Questions & Answers

Renaming files with part of their pathname and copying them to new directory

Hi I think this should be relatively simple but I can't figure it out. I have several files with the same name in different folders within a directory (the output of a program that I ran). Something like this: ./myAnalysis/item1/round1/myoutput.txt ./myAnalysis/item1/round2/myoutput.txt... (2 Replies)
Discussion started by: jullee
2 Replies

4. Shell Programming and Scripting

Renaming Filenames by replacing a part

Hi, I have little experience on Shell scripts, I searched the forum but couldn't make out what I want. I want to rename a set of files to a new file name a_b_20100101 c_d_20100101 ....................... ...................... I want to rename the files to a_b_20140101... (5 Replies)
Discussion started by: JaisonJ
5 Replies

5. Shell Programming and Scripting

Renaming file and check for the renamed file existence

Hi Am trying to move a file from one name to another When I do "ls" to check for the moved filename I can see the file but when I try the same with a script am unable.. I think am doing some pretty silly error.. please help.. toMove=`ls | grep -E "partition.+"` mv $toMove partition._org... (7 Replies)
Discussion started by: Priya Amaresh
7 Replies

6. Shell Programming and Scripting

[Solved] Printing a part of the last line of the specific part of a file

Hi, I have 80 large files, from which I want to get a specific value to run a Bash script. Firstly, I want to get the part of a file which contains this: Name =A xxxxxx yyyyyy zzzzzz aaaaaa bbbbbb Value = 57 This is necessary because in a file there are written more lines which... (6 Replies)
Discussion started by: wenclu
6 Replies

7. Shell Programming and Scripting

File renaming from list of names contained in another file

I have to rename a large number of files so that the name of each file corresponds to a code number that is given side by side in a list (textfile). The list contains in column A the filename of the actual files to be renamed and in column B the name (a client code, 9 digits) that has to be... (7 Replies)
Discussion started by: netfreighter
7 Replies

8. Shell Programming and Scripting

Renaming a file use another file as a sequence calling a shl

have this shl that will FTP a file from the a directory in windows to UNIX, It get the name of the file stored in this variable $UpLoadFileName then put in the local directory LocalDir="${MPATH}/xxxxx/dat_files" that part seems to be working, but then I need to take that file and rename, I am using... (3 Replies)
Discussion started by: rechever
3 Replies

9. Shell Programming and Scripting

Renaming a file

I am a complete Unix newbie and I need some help! (Please...) I need to rename a file from the following format: Test_Test_EAR_1234.ear To the following: Test_Test_EAR.ear In other words, I need to remove everything after & including the final underscore up to the "." What is the best... (6 Replies)
Discussion started by: VeloLisa
6 Replies

10. Shell Programming and Scripting

renaming part of a file

how I can change content ( know it) and part of a file name based on a pattern. i have a file xxx_yyy I also have to change inside contect frm xxx to yyy. I can do that with sed but how i can change the part of file name in the same time processing in for each *; do loop thanks (0 Replies)
Discussion started by: ajaya
0 Replies
Login or Register to Ask a Question