[Solved] Search, Extract and Rename Multiple Files
Hi,
I want perl script for the below requirement.
We have lot of files like below name in the directory
And also we have another file as "Group.csv" in the same directory as per the below format
Script has to get the message id from one the above files (750464921-RE-file2.csv) and search it in the "Group.csv" file if it matches then get the respective Group Name (2nd Column) and add the group name with hypen(-) in the prefix of the file name (HB271_NDM-750464921-RE-file2.csv) like that script has to do for all the files which starts with 750*.csv
Thanks,
Saravanan
Last edited by Don Cragun; 02-26-2014 at 06:39 AM..
Reason: Add CODE tags.
NOTE: Where OUTPUT_ls is the output of command ls -ltr
and filename check_file_names_OUTPUT is the file with your given input and which present in same directory.
EDIT: In place of echo you can use mv command to rename the filenames for same.
Thanks,
R. Singh
Last edited by RavinderSingh13; 02-26-2014 at 06:44 AM..
Reason: Adding solution to rename the files in same
This User Gave Thanks to RavinderSingh13 For This Post:
This only for test purpose
This is also only for test purpose
So these are your files
This is your group file
Contents of group file
Just to print matchup
copy with newnames
Final output ---------- Post updated at 05:47 PM ---------- Previous update was at 05:44 PM ----------
If any of your Group.csv 2nd field values contain a tab character or if any of your original filenames contain a space or tab character, the following might work better:
This code just prints mv commands to be executed. If the output produces the mv commands you want to be run, change the last line in the script to:
to actually move the files.
Note that none of the suggestions presented so far (including the script above) will work correctly if any of the filenames being used as sources or targets for the move contain any dollar-sign ($), double-quote ("), or newline characters.
If you want to run any of these scripts that use awk on a Solaris/SunOS system, use /usr/xpg4/bin/awk, /usr/xpg6/bin/awk, or nawk instead of the default /usr/bin/awk.
Update for new requirements:
To use at most 10 characters in the added prefix, change the line:
to:
Last edited by Don Cragun; 02-26-2014 at 08:57 AM..
Reason: Add changes for new requirements.
Thanks Akshay.
It looks good but i have the below issue Group.csv Output files as per the script Output files should be like below
Thanks Don.
Code is not restricted for the first 10 chars Output file as per your code
Last edited by Franklin52; 02-26-2014 at 10:45 AM..
Reason: Please use code tags
Hey guys,
I have wrote the following script to apply a module named "trinity" on my files. (it takes two input files and spit a trinity.fasta as output)
#!/bin/bash -l
#SBATCH -p node
#SBATCH -A <projectID>
#SBATCH -n 16
#SBATCH -t 7-00:00:00
#SBATCH --mem=128GB
#SBATCH --mail-type=ALL... (1 Reply)
Hey guys, I am the definition of a newbie. I am in the process of trying to rip all my dvds onto a new HTPC I setup. While doing this, I am also trying to organize a bunch of other files I already have to proper naming conventions. So far I have just been naming each file separately (I am on a... (4 Replies)
Hi. I have a large number of files with names like:
t_ 0.20000E-02.dat
There is actually a space after the underscore. These files are numbered numerically, i.e. t_ 0.20000E-02.dat, t_ 0.21000E-02.dat, t_ 0.22000E-02.dat and so on.
What I would like to do is rename such that the file with... (8 Replies)
Hi
I need to reanme the multiple file using unix script
I have multiple file
like:
sample_YYYYMMDD.xls
test new_YYYYMMDD.xls
simple_YYYYMMDD.xls
I need to rename this file
sample.xls
testnew.xls
SIMPLE.xls
thanks (8 Replies)
Hi,
I'd like to process multiple files. For example:
file1.txt
file2.txt
file3.txt
Each file contains several lines of data. I want to extract a piece of data and output it to a new file.
file1.txt ----> newfile1.txt
file2.txt ----> newfile2.txt
file3.txt ----> newfile3.txt
Here is... (3 Replies)
Hi everyone,
I'm very green in Linux.
Please help me to solve my problem.
I have thousands of files and I want to change their names.
They have naming convection: prefix_date_date+1_suffix.nc
prefix: ext-GLORY
date_date+1: 20020101_20020102
and two types of suffix: gridV_R20020130 and... (3 Replies)
Hi all, I have some files like:
pickup.0000043200.t001.t001.data
pickup.0000043200.t001.t002.data
pickup.0000043200.t002.t001.data
pickup.0000043200.t002.t002.data
pickup.0000043200.t003.t001.data
pickup.0000043200.t003.t002.data
I need to rename these files to
... (4 Replies)
Variations of multiple renames seems to come up a lot but i can't find the answer to this situation.
Tidying up a directory where people rename files to .working, .bob, .attempt1 & so on.
what i am trying to do is: list the file type, & rename from ".whatever" to .fixed.
As the ".whatever" is... (5 Replies)
I have several hundred files in one directory which I need to move to another directory with the new extension, for example:
/bb/data/rptmgr* are in the source directory need to be moved to
/bb/data55/rptmgr*.new
Is there an efficient way to do it? Thanks -A (4 Replies)
Hi,
can anyone have a ksh script to rename multiple files (ie to remove .Z extension of the files)
can someone correct this?
for i in *.Z
do
var1 = substr($i, 1,at(".Z",$i)-1)
mv $i $var1
done
Thanks..
Antony (13 Replies)