Multiple File renaming with a twist


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Multiple File renaming with a twist
# 1  
Old 02-03-2015
Multiple File renaming with a twist

Hi

I can do simple file renaming but this task is slightly more troublesome
Ive got a guy that gives me multiple .pdf filles in a directory named
something like

Code:
3412345.pdf
4565465.pdf
8534534.pdf

And he also gives me a html file which is tabled with which shows the filenames above and the titles.
E.G
Code:
England|SolarPanels roof|3412345.pdf
Scotland|SolarPanels Garden|4565465.pdf
Ireland|SolarPanels Wall|8534534.pdf

What I want to do is rename all of the files in the directory to match the titles so I want to rename
Code:
 3412345.pdf to SolarPanels roof.pdf
4565465.pdf to SolarPanels Garden.pdf
8534534.pdf to SolarPanels Wall.pdf

Is there a way I can do this in a shell script which would be quick n easy?!! I can create a .txt file or whaever is needed to be read as input
Any help would save me a lot of time

Last edited by Don Cragun; 02-03-2015 at 09:36 AM.. Reason: Add CODE and ICODE tags.
# 2  
Old 02-03-2015
Hi

1) For future post, use code tags as required by the forum rules!
2) its quick Smilie
Code:
IFS="|"
while read country label pdf
do
    mv "$pdf" "${label}.pdf"
done<textfile.txt

hth
# 3  
Old 02-03-2015
Quote:
Originally Posted by messiah1
Hi

I can do simple file renaming but this task is slightly more troublesome
Ive got a guy that gives me multiple .pdf filles in a directory named
something like

3412345.pdf
4565465.pdf
8534534.pdf
And he also gives me a html file which is tabled with which shows the filenames above and the titles.
E.G
England|SolarPanels roof|3412345.pdf
Scotland|SolarPanels Garden|4565465.pdf
Ireland|SolarPanels Wall|8534534.pdf

What I want to do is rename all of the files in the directory to match the titles so I want to rename
3412345.pdf to SolarPanels roof.pdf
4565465.pdf to SolarPanels Garden.pdf
8534534.pdf to SolarPanels Wall.pdf

Is there a way I can do this in a shell script which would be quick n easy?!! I can create a .txt file or whaever is needed to be read as input
Any help would save me a lot of time
Hello messiah1,

Could you please use code tags for commands/codes/Inputs in your posts as per forum rules, following may help you in same.
Code:
awk -vs="\"" -F"|" '{print "mv " $3 OFS s $2 s}' Input_file

If happy with result of above command you can use following.
Code:
awk -vs="\"" -F"|" '{print "mv " $3 OFS s $2 s}' Input_file | sh

Thanks,
R. Singh
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

File Listing, with a Twist?

Greetings! I have a quick question which must be deferred to those with greater skill than myself :) In this situation, I wish to create a list of all the files on an entire partition in descending order sorted by date. I tried numerous switches for ls, and found this line to be the closest... (4 Replies)
Discussion started by: LinQ
4 Replies

2. Shell Programming and Scripting

Simple two file compare with twist

I have file1 and file2 I lookup field3 from file2 in field1 of file1 and if there is a match, output field 2,3,5 from file2. I now want to add field2 of file1 in the output. I suspect what I have to do is read the entire line of file1 into a 2 dim array? pls help. (1 Reply)
Discussion started by: tmonk1
1 Replies

3. Shell Programming and Scripting

Splitting file into multiple files and renaming them

Hi all, Newbie here. First of all, sorry if I made any mistakes while posting this question in terms of rules. Correct me if I am wrong. :b: I have a .dat file whose name is in the format of 20170311_abc_xyz.dat. The file consists of records whose first column consists of multiple dates in... (2 Replies)
Discussion started by: chanduris
2 Replies

4. Shell Programming and Scripting

Renaming file that has multiple numbers as filename

Hi I have a file with filename as "partition-setup-and-ipl.vtcmd.76217657132.9721536798" Now i need to move this file as "partition-setup-and-ipl.vtcmd.76217657132.9721536798_org" i tried with # ls | grep -E "partition-setup-and-ipl.vtcmd.+"... (2 Replies)
Discussion started by: Priya Amaresh
2 Replies

5. Shell Programming and Scripting

Simple two file compare with twist

I have file1 and file2 I lookup field3 from file2 in field1 of file1 and if there is a match, output field 2,3,5 from file2. I now want to add field2 of file1 in the output. I suspect what I have to do is read the entire line of file1 into a 2 dim array? pls help. here is my code: ... (9 Replies)
Discussion started by: jack.bauer
9 Replies

6. UNIX for Dummies Questions & Answers

file count with a twist

Hello Everyone, I am using the korn shell. I was hoping to find a set of commands to count files in a directory. I am using: ls /home/name/abc* | wc -l This command works fine when a file matches abc* (returns only the file count) , however when no file(s) are found I get... (2 Replies)
Discussion started by: robert4732
2 Replies

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

8. UNIX for Dummies Questions & Answers

Multiple file renaming

Hi All, I have a number of files in a directory that I would like to rename - I am quite aware that you can use the mv command to rename the files - I would like to rename them automatically from the command line instead of having to do them singly. I have searched the forum pertaining to... (4 Replies)
Discussion started by: BigTool4u2
4 Replies

9. Shell Programming and Scripting

Renaming multiple files

hi, I've a machine running RHEL3,kernel version 2.4. i need to rename multiple files under one directory as follows: ls demo.c demo.S demo-1243.sw demo.xyz and now i need to replace the occurrence of demo with demo_1 for each of the above file. the tedious way is to go ahead and do mv on... (2 Replies)
Discussion started by: amit4g
2 Replies

10. Shell Programming and Scripting

Renaming multiple files

Can someone please tell me how I can rename a bunch of files at a time. I hava a directory that has 700+ files that are named *.xyz and I would like to rename them to *.abc . How can I do that with a simple command ? mv *.xyz *.abc did not work. Thanks in advance (4 Replies)
Discussion started by: jxh461
4 Replies
Login or Register to Ask a Question