Renaming files - error


Login or Register for Dates, Times and to Reply

 
Thread Tools Search this Thread
Top Forums UNIX for Beginners Questions & Answers Renaming files - error
# 8  
Thanks Rudic.


It working perfectly.Can you explain the below code.


Code:
 t=${i/"file"/"newfile"}

--- Post updated at 12:27 PM ---

Hi Don,


Apologies for delay message. My request is simple and below shown and rudic code worked.


i/p


Code:
atomic@atomic-VirtualBox:~/Shell_Practice/rename$ ls -lrt
total 8
-rw-r--r-- 1 atomic atomic   0 Jan 25 22:55 file2.txt
-rw-r--r-- 1 atomic atomic   0 Jan 25 22:55 file1.txt
-rw-r--r-- 1 atomic atomic   0 Jan 25 22:55 file3.txt
-rw-r--r-- 1 atomic atomic   0 Jan 25 22:55 file4.txt
-rw-r--r-- 1 atomic atomic   0 Jan 25 22:55 file6.txt
-rw-r--r-- 1 atomic atomic   0 Jan 25 22:55 file5.txt
-rw-r--r-- 1 atomic atomic   0 Jan 25 22:55 file7.txt
-rw-r--r-- 1 atomic atomic   0 Jan 25 22:55 file8.txt
-rw-r--r-- 1 atomic atomic   0 Jan 25 22:55 file9.txt
-rw-r--r-- 1 atomic atomic   0 Jan 25 22:55 file10.txt
-rwxr-xr-- 1 atomic atomic 117 Jan 26 22:08 rename.sh
-rwxr-xr-- 1 atomic atomic 125 Jan 30 21:36 myrename.sh


output


Code:
atomic@atomic-VirtualBox:~/Shell_Practice/rename$ ls -lrt
total 8
-rw-r--r-- 1 atomic atomic   0 Jan 25 22:55 newfile2.txt
-rw-r--r-- 1 atomic atomic   0 Jan 25 22:55 newfile1.txt
-rw-r--r-- 1 atomic atomic   0 Jan 25 22:55 newfile3.txt
-rw-r--r-- 1 atomic atomic   0 Jan 25 22:55 newfile4.txt
-rw-r--r-- 1 atomic atomic   0 Jan 25 22:55 newfile6.txt
-rw-r--r-- 1 atomic atomic   0 Jan 25 22:55 newfile5.txt
-rw-r--r-- 1 atomic atomic   0 Jan 25 22:55 newfile7.txt
-rw-r--r-- 1 atomic atomic   0 Jan 25 22:55 newfile8.txt
-rw-r--r-- 1 atomic atomic   0 Jan 25 22:55 newfile9.txt
-rw-r--r-- 1 atomic atomic   0 Jan 25 22:55 newfile10.txt
-rwxr-xr-- 1 atomic atomic 117 Jan 26 22:08 rename.sh
-rwxr-xr-- 1 atomic atomic 121 Jan 30 21:38 myrename.sh

# 9  
Quote:
Originally Posted by nag_sathi
...
It working perfectly.Can you explain the below code.
Code:
 t=${i/"file"/"newfile"}

...
As I said in my post, that's called "parameter expansion" in shell. man bash:
Quote:
Parameter Expansion
.
.
.
${parameter/pattern/string}
Pattern substitution. The pattern is expanded to produce a pattern just as in pathname expansion. Parameter is expanded and the longest match of pattern against its value is replaced with string. ...
Login or Register for Dates, Times and to Reply

Previous Thread | Next Thread
Thread Tools Search this Thread
Search this Thread:
Advanced Search

Test Your Knowledge in Computers #235
Difficulty: Easy
The ARPANET was operated by the military during the two decades of its existence, until 1990.
True or False?

9 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Renaming multiple files in sftp server in a get files script

Hi, In sftp script to get files, I have to rename all the files which I am picking. Rename command does not work here. Is there any way to do this? I am using #!/bin/ksh For eg: sftp user@host <<EOF cd /path get *.txt rename *.txt *.txt.done ... (7 Replies)
Discussion started by: jhilmil
7 Replies

2. Shell Programming and Scripting

renaming files

Hi, I have a list of files in a folder with the same name ending (over 1000 files) joe.jpy.jpeg joe1.jpy.jpeg joe2.jpy.jpeg jon3.jpy.jpeg jor5.jpy.jpeg .....jpy.jpeg etc. I want to change jpy to hhk So the output will be: joe.hhk.jpeg joe1.hhk.jpeg joe2.hhk.jpeg jon3.hhk.jpeg... (3 Replies)
Discussion started by: kylle345
3 Replies

3. UNIX for Dummies Questions & Answers

Renaming Files With 2 .

Dear All expertise.. just wanna ask if there is a way on how to change the filename as per below sample:- filename:- cob120514093156.03.466926330 CCBS-CPMM_SEND_COB_120514_100549_3.rpt to convert to:- cob120514093156.03.466926330.bd (rename from cob120514093156.03.466926330) ... (17 Replies)
Discussion started by: yokomo
17 Replies

4. UNIX for Dummies Questions & Answers

Renaming all files

Hi, Very silly question. I need to rename all my files located in one particular folder. The names are Results1.dis, Results2.dis, Results3.dis, etc. I need to change the names to Results001.dis, Results002.dis, Results003 so on and so forth. Now, Files with double digits such as Results17.dis... (3 Replies)
Discussion started by: Xterra
3 Replies

5. Linux

Renaming files

Hello, I have some files which I would like to rename. These files are generated every 15 min and i would like to issue script that originally rename this file with one prefix like "BBB91." original file is : C20110415.1315-20110415.1330 desired one would be: ... (2 Replies)
Discussion started by: arihali
2 Replies

6. Shell Programming and Scripting

renaming files or adding a name in the beginning of all files in a folder

Hi All I have a folder that contains hundreds of file with a names 3.msa 4.msa 21.msa 6.msa 345.msa 456.msa 98.msa ... ... ... I need rename each of this file by adding "core_" in the begiining of each file such as core_3.msa core_4.msa core_21.msa (4 Replies)
Discussion started by: Lucky Ali
4 Replies

7. UNIX for Advanced & Expert Users

renaming files

How can I rename files with .c to .cpp in my current directory and if any directory present in current directory system should descend in to that and checks ( find ).... tell me how to achieve this using find command and other if any? thanks. (7 Replies)
Discussion started by: shahnazurs
7 Replies

8. Shell Programming and Scripting

Getting error by renaming all the files in a folder

Hi All, I have a folder name as postscript folder and it contains the following postscript files. package1.ps package2.ps package3.ps when i am renaming all the ps files to xps files by using the following command mv /postscript/*.ps /postscript/*.xps Then i am getting the... (4 Replies)
Discussion started by: sunitachoudhury
4 Replies

9. UNIX for Dummies Questions & Answers

renaming files

directory name = /usr/tom/1997 files - ABC_1997_ST1_BCD.SQL BCD_1997_ST1_EFG_SAB.SQL TTT_EBC_1997_ST1_A.SQL sub directory - /usr/tom/1997/jan a) I want to just rename the all files ending with '.SQL' and also its contents in the 1997 directory(excluding subdirectories eg... (3 Replies)
Discussion started by: systemsb
3 Replies

Featured Tech Videos