Renaming the extension of a set of files


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Renaming the extension of a set of files
# 1  
Old 06-21-2012
Renaming the extension of a set of files

Hi All,

I am trying to rename the extension of a set of file from .txt to .xtx. When I run the following script,

Code:
#!/bin/sh
l=`ls /f`
for f in $l
do "mv $f ${f%.txt}.xtx" ;
done

a file such as 1.txt is renamed to 1? where ? is a strange character. Could you please help me fix the code without using other commands such as awk or tr or ...?

Best regards,
Sara

Last edited by Scrutinizer; 06-22-2012 at 02:00 AM.. Reason: code tags
# 2  
Old 06-22-2012
Code:
#! /bin/bash

cd /path/to/txt/files
for f in *.txt
do
    mv $f ${f%.txt}.xtx
done

# 3  
Old 06-22-2012
The double quotes are in the wrong places:
Code:
mv "$f" "${f%.txt}.xtx"

also
ls /f means that there is a directory called "/f" in the root?
# 4  
Old 06-22-2012
Thanks all but none of the solution works. Still I am getting the same result. Anyone?
Login or Register to Ask a Question

Previous Thread | Next Thread

9 More Discussions You Might Find Interesting

1. UNIX for Dummies Questions & Answers

Display the .csv extension files based on .done extension fine

Hi All, I want to fetch the files based on .done file and display the .csv files and Wil take .csv files for processing. 1.I need to display the .done files from the directory. 2.next i need to search for the .Csv files based on .done file.then move .csv files for the one directory ... (2 Replies)
Discussion started by: girija.g6
2 Replies

2. Shell Programming and Scripting

Help needed with shell script to search and replace a set of strings among the set of files

Hi, I am looking for a shell script which serves the below purpose. Please find below the algorithm for the same and any help on this would be highly appreciated. 1)set of strings need to be replaced among set of files(directory may contain different types of files) 2)It should search for... (10 Replies)
Discussion started by: Amulya
10 Replies

3. Shell Programming and Scripting

move set of files to the target path with different extension

I have the following files in the dir /home/krishna/datatemp abc.xml cde.xml asfd.txt asdf_20120101-1.xml asdf_20120101-2.xml asdf_20120101-3.xml asdf_20120101-4.xml Now I need to move the files having the pattern asdf_20120101-*.xml to the dir /home/krishna/dataout with the extn as... (1 Reply)
Discussion started by: kmanivan82
1 Replies

4. Shell Programming and Scripting

Finding compound words from a set of files from another set of files

Hi All, I am completely stuck here. I have a set of files (with names A.txt, B.txt until L.txt) which contain words like these: computer random access memory computer networking mouse terminal windows All the files from A.txt to L.txt have the same format i.e. complete words in... (2 Replies)
Discussion started by: shoaibjameel123
2 Replies

5. Shell Programming and Scripting

Renaming a file and keep the extension of file as it is

Hi, I am trying to rename multiple filenames in a UNIX directory matching a specific condition. i=0 for file in `ls $filename` do echo "$file" #echo $i i=`expr $i + 1` mv $src_dir/${file} $src_dir/${file}_${i} done But this code renames the filenames and... (9 Replies)
Discussion started by: chetancrsp18
9 Replies

6. Solaris

metaset - renaming /editing the set name - possible ?

Hi all I need to change my current metaset setname from lh-rms02ds to lh-lgwrms01ds. Is it possible ?? I know within veritas I do a vxedit, is there a way in SVM ? I notice theres a metarename, but this is for the metadevice level. Any tips ? help ?? Or do I need to delete /... (2 Replies)
Discussion started by: sbk1972
2 Replies

7. Shell Programming and Scripting

bad substitution Error while renaming Extension

Hi All, We are in the process of Migrating from AIX 4 to Solaris 10 and getting a Few Errors. I have been programming in shell but could never establish muself as an expert, hence please need you help. I am Getting Bad Substitution error in my script, I have isolated the issue and its... (6 Replies)
Discussion started by: paragkhanore
6 Replies

8. UNIX for Dummies Questions & Answers

Removing prefix from multiple files and renaming file extension

Hello i have the files in this format pdb1i0t.ent pdb1lv7.ent pdb1pp6.ent pdb1tj2.ent pdb1xg2.ent pdb2b4b.ent pdb2ewe.ent Now i have to remove the prefix pdb from all the files and also i need to change the extension of .ent to .txt The new file should look like this ... (3 Replies)
Discussion started by: empyrean
3 Replies

9. UNIX for Dummies Questions & Answers

Renaming multiple files, to get rid of extension

I have a good script to rename multiple files, but what's the best way I can remove some text from multiple filenames? Say I have a directory with 35 files with a .XLS at the end, how can I rename them to remove the .XLS but keep everything the same, without having to mv manually. Thanks. (6 Replies)
Discussion started by: nj78
6 Replies
Login or Register to Ask a Question