Change the file name and copy old file content to new file names.

Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Change the file name and copy old file content to new file names.
# 1  
Old 11-22-2013
Change the file name and copy old file content to new file names.


I have a files in a directory as below :-
ls -1

Whereever i have S1STC i need to copy them into new file with file name S2STC.

expected output :-
ls -1

Thanks in advance.

Moderator's Comments:
Mod Comment Please add CODE tags where appropriate and stop depending on moderators to clean up your posts for you.

Last edited by Don Cragun; 11-22-2013 at 05:56 AM.. Reason: Add CODE tags.
# 2  
Old 11-22-2013
Try this!!!

Assuming you have perl option,

ls *S1STC* | perl -nle '$x=$_;s/S1STC/S2STC/;system "cp $x $_"'

Or if you want a looping structure, use below code,

for foobar in `ls *S1STC*`;
temp=`echo "$foobar" | sed 's/S1STC/S2STC/g'`
cp "$foobar" "$temp" ;

Hope this helps!!!
# 3  
Old 11-22-2013
Thanks varathaneie Smilie
code is working.
# 4  
Old 11-22-2013
There's many solutions for your problem, posted before in these fora, so an advance searching here could have been quite helpful... Try this as well (the pattern substitution expansion may not be available in all shells):
for i in *S1ST*; do echo cp $i ${i/S1/S2}; done

Remove echo when happy with the results...
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. UNIX for Beginners Questions & Answers

Copy the content from txt file and create a html file

I have a txt file with a list of error messages in a xml tag format, and each error message is separated with a identifier(endresult).Need to split that and copy and create a new html file.Error message has some special character. how to escape the special character and insert my data into the... (7 Replies)
Discussion started by: DevAakash
7 Replies

2. Shell Programming and Scripting

Copy content of file in different file

Dear all, I get a file which is probably in hexadecimal character which i have to load in oracle. oracle is unable to process the original file but when i copy the content into notepad it works fine. How can i achieve in unix to copy content of file into .txt file instead of cp command as cp... (23 Replies)
Discussion started by: guddu_12
23 Replies

3. Shell Programming and Scripting

Script to change file names

I have a landing directory on my unix (solaris) server, that receives the following files: MLH4301I AAOT-hhslog.610.20150805.txt MLH4301I AAOT-hhslog.611.20150805.txt MLH4301I AAOT-hhslog.612.20150805.txt MLH4301I AAOT-hhslog.613.20150805.txt and I need to add to this files the number 10000... (6 Replies)
Discussion started by: fretagi
6 Replies

4. UNIX Desktop Questions & Answers

copy content of file to another

I have a file called part1.pdb...contents are: ATOM 1 N SER 1 -10.295 -8.909 10.913 1.00 0.00 ATOM 2 H1 SER 1 -10.230 -8.214 10.183 1.00 0.00 ATOM 3 H2 SER 1 -9.558 -8.745 11.584 1.00 0.00 ATOM 4 H3 SER 1 -11.255 ... (1 Reply)
Discussion started by: kanikasharma
1 Replies

5. UNIX for Dummies Questions & Answers

How to copy entire file content into another file being in last line mode of vi ?

How to copy entire file content into another file being in last line mode of vi ? ---------- Post updated at 10:07 AM ---------- Previous update was at 09:56 AM ---------- Got it : :1,30w file.txt (1 Reply)
Discussion started by: presul
1 Replies

6. UNIX for Dummies Questions & Answers

copy content of file to other file

Hi , i Have 11 Gb file which contain 70 database but I want only one database now i want content of file copy to other file as from starting from word of file1 create database xyz to end word create database xyz1 this copies to other file2 By this I cant get required database... (2 Replies)
Discussion started by: kaushik02018
2 Replies

7. Shell Programming and Scripting

How to copy Content of a file to another file on a specific column

Hi i have a file (file1)with this content: and a second file (file2) with a content wich have 8 Columns if a do a awk '{print $8}' file2 i become this output: ,'', So i want to replace only the in file2 (column 8) with the information... (8 Replies)
Discussion started by: tuxus
8 Replies

8. AIX

find for specific content in file in the directory and list only file names

Hi, I am trying to find the content of file using grep and find command and list only the file names but i am getting entire file list of files in the directory find . -exec grep "test" {} \; -ls Can anyone of you correct this (2 Replies)
Discussion started by: madhu_Jagarapu
2 Replies

9. UNIX for Dummies Questions & Answers

Change All File Names in a Directory

Hi, If I have a directory full of say 100 random files, and I would like to organize them, for example: FILE001, FILE002, FILE003, FILE004, etc. How would I do this from Terminal, instead of manually changing each file? I'm using Mac OS X, if that makes a difference. Thank you in advance... (8 Replies)
Discussion started by: andou
8 Replies

10. Shell Programming and Scripting

How to change automatically the file names

Hi all, I need to replace automatically all special characters of one filename with some corresponding characters For example > --> oe --> ae .... If the special character comes more than one time, then all the coccuerences have to be replaced. I would like to have a... (6 Replies)
Discussion started by: MAKY
6 Replies
Login or Register to Ask a Question