File renaming from list of names contained in another file
I have to rename a large number of files so that the name of each file corresponds to a code number that is given side by side in a list (textfile).
The list contains in column A the filename of the actual files to be renamed and in column B the name (a client code, 9 digits) that has to be assigned to the file.
Listfile:
file-abcd.pdf #to be renamed [tab] 123456789 #the new filename
file-abce.pdf #to be renamed [tab] 809809231 #the new filename
a.s.o
It's to say "for F in each actual file in files/ named like this on the left, re-name it to the name to the right and keep the old extension... But bash did not understand this phrase )
The names to be given are stored in a file but the files to name are actual files, so just no idea how to tackle this and where to even start.
So far all the scripting I could do and understand in bash was loops to rename just an extension to a file, or to add an extra suffix. Beginner... sigh... But there has to be a way to do it in Linux, there usually is.
Thanks in advance for your help!
Anyway if your file looks like that second example, then this should work:
[/QUOTE]
1/ thanks!
2/ yes, the file looks like in the second example, it is a simple copy-paste of two columns from a spreadsheet to a text file.
3/ however, there is a small issue - caused by my attempt to keep the example simple; in fact the files have longer names with lots of dahses in them "-" like so:
acme-doc-may-00101.pdf 2336909
acme-doc-may-00102.pdf 2336910
acme-doc-may-00103.pdf 2336911
some are even longer
acme-doc-may-bclot-00104.pdf 2336912
Apologies, I wanted to keep it all lean in the example.
this causes a little problem, the renamed files have an extra dot in the filename after running your command:
acme.2336909.pdf
acme.2336910.pdf
acme.2336911.pdf
In other operating systems it would be a problem to have two dots, so best to have an underscore instead.
I tried to edit your command but messed up results, of course
Hi, I have about 60 files in a directory and need to rename those files. For example the file names are
i_can_phone_yymmdd.txt (where yymmdd is the date. i.e 170420 etc)
i_usa_phone_1_yymmdd.txt
i_eng_phone_4_yymmdd.txt
The new file names should be
phone.txt
phone_1.txt
phone_4.txt
I am... (4 Replies)
Hi, I have a control file which will contain all filenames(300) files. Loop through all the file names in the control files and check the existence of this file in another directory(same server). I need to infinitely(2 hrs) run this while loop until all the files are found. Once a file is found,... (5 Replies)
Below is my script code.which shows the environment name and then fetch the file from the ftp server but I am facing one issue.The script should be run in both way.We can pass the arguments with script and select the environment name then file name.Here the issue is I am not able to list the files... (1 Reply)
Hi Team,
I'm new to Unix shell scripting .
I've the following requirement
A folder contains the list of files with the following format
ab.name.11.first
ab.name.12.second
ab.name.13.third
----------
I have to rename the above file to like below
... (6 Replies)
Hi there,
Firstly, I have no experience with shell scripts so would really appreciate some help.
I have the following shell script that is causing some problems:
moveit()
{
&& set -x
if
then
DOUBLE_DELIVERY=$(grep... (6 Replies)
Hi Guys,
I have a small problem of renaming multiple files. For example I have names of a set of files in one directory like
K2_34625-34675
K7_988963-988983
K12_773882-7734102
and the other set corresponding to the same is
U_P_321_9_3_11.ab1
U_P_322_9_3_11.ab1
U_P_323_9_3_11.ab1
Now... (23 Replies)
I have the following list of file names stored in $fnames, so that if I do
foreach f ($fnames)
echo "$f"
end
I will get
n02-z30-sr65-rgdt0p50-dc0p002-16x12drw-run1
n02-z30-sr65-rgdt0p50-dc0p002-16x12drw-run2
n02-z30-sr65-rgdt0p50-dc0p002-16x12drw-run3... (3 Replies)
I have 7 files with 7 different names coming into a specified folder on weekly basis, i need to pick a file one after another and load into oracle table using sql loader. I am using ksh to do this. So in the process if the file has error records and if sql loader fails to load into oracle tables,... (2 Replies)
I want to write a shell script that will rename all the file names to today's date attached to it..
so for example i have a file names like
file1.sales.20081201.txt.c
zbrs.salestxtn.20091101.txt.inn
then it will rename both the files with todays date to it so the file names get changed... (1 Reply)
Hi,
I am trying to find the content of file using grep and find command and list only the file names
but i am getting entire file list of files in the directory
find . -exec grep "test" {} \; -ls
Can anyone of you correct this (2 Replies)