Renaming of .txt files


 
Thread Tools Search this Thread
Top Forums UNIX for Dummies Questions & Answers Renaming of .txt files
# 1  
Old 04-20-2009
Renaming of .txt files

Hi Guys,

I am a newbie to Unix . I am going through Unix Commands. I have a issue . Please try to find a solution for this...

Example: I am in my current directory now which contains a folder name 'Test' . The folder Test contains some files with .txt extension.Inside the Test folder I am having some more sub-folders.The sub-folders also contain some .txt files. My aim is to rename all the .txt files in Test folder and its subdirectories to .my extension from my current directory.

Example:

[mraghunandanan@localhost ~]$ ls
999 lkj Public sedscript1 Test
Desktop lop qwe Session_01222009 til00
Documents Mail return_sqlvalue.ksh si00 til01
Download ml SCRIPTSER si01 Videos
file.sql Music sdf sort vishwan
insert_file.sql.sql my_jil sdft00 syed workspace
jj1 p1.pl sdft01 tail
jj.gz Pictures sedfile Templates


[mraghunandanan@localhost Test]$ ls
cc hh.txt kk.txt ll.txt mm.txt nn.txt test1 test2 test3

So , Test is the folder which contains .txt files and test1 ,test2 and test3 are subfolders which contains .txt files.

Please help me guys...

Its very important for me...

Ur help will be appreciated...

Regards,

Mahesh..
# 2  
Old 04-20-2009
Code:
find ./Text -type f -name '*.txt' |
while read filename
do
mv $file ${file%%.txt}.my
done

# 3  
Old 04-20-2009
Hi JIm,

I tried ur solution... But not able to get the expected output....

Regards,

Mahesh..
# 4  
Old 04-21-2009
try this in ksh

====code==========
find ./Test -type f -name '*.txt' > file1


while read line
do
mv $line $line.my
done < file1

echo "Renamed files to *.my"
# 5  
Old 04-21-2009
Try the following ...
Code:
curdir=`pwd`
for filename in `find ./Test -type f`
do
cd $curdir
echo "filename: $filename"
cd `dirname $filename`
oldfilename=$filename
echo "oldfile: $oldfilename"
newfilename=`basename $filename .txt`
echo "newfile: $newfilename"
pwd;
mv $newfilename.txt $newfilename.myextension
done

# 6  
Old 04-21-2009
Quote:
Originally Posted by thegeek
Try the following ...
Code:
curdir=`pwd`
for filename in `find ./Test -type f`
...

use a while loop
Code:
find ./Test -type f | while read FILE
do
 ...
done

 
Login or Register to Ask a Question

Previous Thread | Next Thread

10 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

Compare two txt files,mismatches will be in new txt files

Hi, Below are the sample data for txt files. txt file 1 Partnumber|catgroup_id 10001082|46016 10001093|4680 10001093|386003 10001093|463004 10003251|683 10003251|63005 10003252|463005 10003252|4683 10003260|463005 10003260|4683 10003264|4683 10003264|463005 13420000|67... (5 Replies)
Discussion started by: Ankita Talukdar
5 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. 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

5. 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

6. Solaris

list files .txt and .TXT in one command

Dear experts, In a directory i have both *.TXT and *.txt files. I have a script- for file in `ls *.txt`; do mv $file /tmp/$file How to list both *.txt and*.TXT file in one command so that script will move both .txt or .TXT whatever it find. br//purple (4 Replies)
Discussion started by: thepurple
4 Replies

7. UNIX for Dummies Questions & Answers

Need help renaming files

I just can't figure this one out. I have a lot of files name (for example) ABC1234.5678.ext I need to rename these files U0105678PQRS So I'm removing everything before the first "." I'm keeping "5678" in the file name Adding "U010" to the front of "5678" Dropping the ".ext" extension ... (5 Replies)
Discussion started by: bbbngowc
5 Replies

8. UNIX for Dummies Questions & Answers

echo "ABC" > file1.txt file2.txt file3.txt

Hi Guru's, I need to create 3 files with the contents "ABC" using single command. Iam using: echo "ABC" > file1.txt file2.txt file3.txt the above command is not working. pls help me... With Regards / Ganapati (4 Replies)
Discussion started by: ganapati
4 Replies

9. UNIX for Dummies Questions & Answers

renaming the files

Hi All, Today I got a small problem while handling zipped files in PROD support. There are files in this format and I had to grep them reading some contents A.B.gz.C.D where A,B,C and D stand for variables (like FIRST.NAME.gz.MIDDLE.LAST). I know that these files are zipped files and If I... (1 Reply)
Discussion started by: adurga
1 Replies

10. UNIX for Dummies Questions & Answers

renaming files

i have a set of *.lst files. now i want to change the names from "lst" to "dat". how to do it? ex.: -rw-r--r-- 1 rram group 22 Sep 21 13:10 a.lst -rw-r--r-- 1 rram group 22 Sep 21 13:09 b.lst -rw-r--r-- 1 rram group 22 Sep 21 13:10 c.lst... (4 Replies)
Discussion started by: raguramtgr
4 Replies
Login or Register to Ask a Question