Need help renaming bulk file extentions


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Need help renaming bulk file extentions
# 1  
Old 05-08-2008
Need help renaming bulk file extentions

Hello,

I am trying to rename bulk files however i dont think the rename/mv command is giong to help me here. here is a quick snapshot of the files I need to rename:


75008040 -rw-r----- 1 root root 8716 May 8 05:00 10.9.144.2
75008041 -rw-r----- 1 root root 11700 May 8 05:00 10.9.160.2
75008042 -rw-r----- 1 root root 9019 May 8 05:00 10.9.16.2
75008043 -rw-r----- 1 root root 10011 May 8 05:00 10.9.176.2

I would like the files to look lik this when done:

75008040 -rw-r----- 1 root root 8716 May 8 05:00 10.9.144.2.txt
75008041 -rw-r----- 1 root root 11700 May 8 05:00 10.9.160.2.txt
75008042 -rw-r----- 1 root root 9019 May 8 05:00 10.9.16.2.txt
75008043 -rw-r----- 1 root root 10011 May 8 05:00 10.9.176.2.txt


I think the issues is that thre are many dots int he filename and mv/rename doest understand that. Not suree what I can do. My goal is to figure out he cmmand and run a cron job to do this daily as new files are writin. Thanks in advance for any suggestions.
# 2  
Old 05-08-2008
Simply use a loop, quote, and * wildcard will expand to every filename starting with 10:

Code:
for i in 10.*; do mv "$i" "$i".txt; done

# 3  
Old 05-08-2008
Hi there,

I'm not close to my Linux Box, but I think the dots has no problem :

for i in `ls -l | awk '{ print $NF}'`
do
mv $i $i".txt"
done

Check on dummy files before, my code isn't checked.Smilie
# 4  
Old 05-08-2008
Quote:
Originally Posted by rubin
Simply use a loop, quote, and * wildcard will expand to every filename starting with 10:

Code:
for i in 10.*; do mv "$i" "$i".txt; done

thanks for the quick response but I am a linux newb. Where would I write this code?
# 5  
Old 05-08-2008
The above two solution would add .txt to the file names.

But, as Jallan mentioned - he/she would be running a cron job everyday to add .txt to the new files add to that directory.

The above codes will also add .txt to the files that already have .txt extension.

So I guess first is to get file names that do no have .txt extension and then update them.
# 6  
Old 05-08-2008
Quote:
Originally Posted by hemangjani
The above two solution would add .txt to the file names.

But, as Jallan mentioned - he/she would be running a cron job everyday to add .txt to the new files add to that directory.

The above codes will also add .txt to the files that already have .txt extension.

So I guess first is to get file names that do no have .txt extension and then update them.
Actually my cron job would delete all files first and add the new files then add .txt. But im not sure how to write this code in a cron jobSmilie
# 7  
Old 05-08-2008
Check out the below post on cron and crontab:

https://www.unix.com/answers-frequent...n-crontab.html

Lets see what kind of questions you have after that..
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. UNIX for Beginners Questions & Answers

Zenity and bulk file movements

Hi all. Total beginner to Zenity. I've plagiarised bits of code from all over to try to get something to work. The story: I have a directory with maybe 10-15 files in it, each about 200MB. i send these files one at a time to a drive about 15 miles away. The Synology sync can only handle... (0 Replies)
Discussion started by: Alfitch
0 Replies

2. UNIX for Dummies Questions & Answers

Bulk changing of file names using Terminal in OS X

I want to change the name of several files within a folders (directory) and subdirectories in OS X. If I only wanted to change file names within the directory I guess I would use: rm photo*.jpg picture*.jpg I have lots of subdirectories, is there a way of getting the file changes for all... (5 Replies)
Discussion started by: ademanuele
5 Replies

3. Shell Programming and Scripting

How to select bulk of info from log file?

unix : sun shell : bash i need to select multiple rows with this format : <special format> 10 lines /<special format> from log file that have lots of info i thought of getting the number of the first line using grep -n "special format" file | cut -d: -f1 then pass it to shell... (2 Replies)
Discussion started by: scorpioneer
2 Replies

4. Shell Programming and Scripting

Renaming files in bulk.

Hi, I have a bunch of files which are named something like: Company Name~1234~X1234~X1-123.pdf I need to get them renamed something like: Company Name~1234(X1234)X1-123.pdf Once I have the X1234 inside () I have a piece of software which can use the X1234 bit. I will be receiving... (7 Replies)
Discussion started by: jcborland
7 Replies

5. Shell Programming and Scripting

Renaming bulk directories and subfiles

Hi, I have a directory with 100 subdirectories and each of these subdirectories has 1 file. Now I have to rename all these. The structure is "files directory has 100 SRR191639-SRR191718 subfolders and in each there is a file with the same name a subdirectory followed by .sra extension... (5 Replies)
Discussion started by: Diya123
5 Replies

6. UNIX for Dummies Questions & Answers

regularly copy files to different directory with different file extentions

I have a NAS and I upload my videos to it from time to time. the video format is 3gp but my media player PBO could only play avi. I want to copy these files to different directory and change the extention from 3gp to avi. (yes I want to keep the original version and create a duplicate version with... (0 Replies)
Discussion started by: momentum
0 Replies

7. Shell Programming and Scripting

bulk renaming of files in sftp using script

Hi, Am using sftp (dsa method) to transfer 20 files from one server(sftp) to another (local). After the transfer is complete the files in the sftp server has to be renamed from .txt extension to .done extension ( aa.txt to aa.done, bb.txt to bb.done and likewise...). I tried rename command... (4 Replies)
Discussion started by: Sindhuap
4 Replies

8. Shell Programming and Scripting

How to bulk changing partial file name in Linux?

I have a bunch of database files in a directory. Their name are like: 1234_ABCD_01.dbf, 28hrs_ABCD_02.dbf I want to change them in bulk to: 1234_XXXU_01.dbf, 28hrs_XXXU_02.dbf. I mean I just want to replace ABCD by XXXU. don't change other part of the file name and the contents of the... (4 Replies)
Discussion started by: duke0001
4 Replies

9. Shell Programming and Scripting

extract bulk emails into a single flat file

Hello Can someone guide me how to extract bulk emails into a single flat file ? We receive mails (approx 1K daily ). I want the contents of the emails for 'current date' to be dumped into one single text file. Please help. (1 Reply)
Discussion started by: Amruta Pitkar
1 Replies

10. Programming

How to read specific lines in a bulk file using C file Programming

Please Help me I have a Bulk file containing Hex data I want to read specific lines from that bulk file by ID number. example ID DATE Time data 14 2005/09/28 07:40:08.546 0 5 078B1C 01916C 0FE59C 004B54 0A9670 0D04ED 05B6B4 0E2223... (10 Replies)
Discussion started by: rajan_ka1
10 Replies
Login or Register to Ask a Question