Please, try the following. If you like the output, comment the line that print and remove the comment on the line that says move.
This script parses the input file and works on each directory identified as the last line in each paragraph.
Last edited by Aia; 11-27-2016 at 11:34 PM..
Reason: Comment about the script.
files in /home/cmccabe/Desktop/index/R_2016_09_21_14_01_15_user_S5-00580-9-Medexome
desired output
while in post #7 you said:
Quote:
Files in directory being updated in dir: R_2016_09_21_14_01_15_user_S5-00580-9-Medexome
input
The identifier is in $2 of the input file. That is what the file in dir should be updated with. The $1 value will match the file name (before it is renamed).
So using the dir in the example:
So, your original request was to rename MEV21.bam to IonXpress_007.bam and MEV21.vcf to IonXpress_007.vcf.
Now the request is to rename IonXpress_007.bam to MEV21.bam, IonXpress_007.vcf to MEV21.vcf, andIonXpress_007.bam.bai to MEV21.bam.bai.
In other words the request has changed from moving two files with fixed length suffixes per prefix to moving three files with varying length suffixes per prefix and the direction of movement has changed from moving from $2 to $1 to moving from $1 to $2.
There is absolutely no reason given for adding all of the rename commands into your script which seem to be complete no-ops (assuming that the files that are in your folder have the names you say they have with just a prefix found in $1 in input and one of the three suffixes above).
Is there a reason why you need those rename commands in your script? Do your existing filenames contain additional characters between the prefixes in input and the three suffixes you want to process? If so, can a <period> ever be one of those additional characters?
Why is it so important that only one directory be processed at a time instead of renaming the files in all of the subdirectories in one run of your script?
Does Aia's suggestion do what you need? Or is something else still required?
This User Gave Thanks to Don Cragun For This Post:
Is there a reason why you need those rename commands in your script? Do your existing filenames contain additional characters between the prefixes in input and the three suffixes you want to process? If so, can a <period> ever be one of those additional characters?
Why is it so important that only one directory be processed at a time instead of renaming the files in all of the subdirectories in one run of your script?
Does Aia's suggestion do what you need? Or is something else still required?
My file names do contain many other additional characters that are removed in the rename. A <period> is not one of them however.
There are a few reasons to process only one directory at a time.
1. Since I am a clinical scientist it is important to only process and log one directory
2. Only the oldest directory is processed by the bash in the beginning
3. Since many of the lines repeat duplicates may exist, however the current directory is unique in input
Aia's code works except I am getting:
line 29 is the grep. Thank you very much
Below is the bash used to run the code and ensure the current directory is used:
Last edited by cmccabe; 11-28-2016 at 11:09 AM..
Reason: added bash
Those messages are for the directories in the input file that it can not read. I did not want to stop the program at the first time that entries in the input file does not contain an available path.
Please, replace || for or and they will go away.
Instead of:
This:
[/CODE]
Please, use the code outside the bash file. I read your other threads and the program does not require for you to rename them. It will work even if they are originally as:
The program does not require to be cd'ed into a particular directory nor does depend of any transformation. Just make sure that the directory lines are correct in the input file. And that these directories live under the path: /home/cmccabe/Desktop/index or you need to change that where is says "change as needed."
The script does run without error now, however the files do not update in the directory. Below is the code I use the perl is run before the bash
Is this correct or am I missing something? Thank you for all of your help .
/home/cmccabe/s5_files/identifier/input
current directory /home/cmccabe/Desktop/index/R_2016_09_21_11_26_19_user_S5-00580-8-Medexome
after script is run files are renamed to:
after script is run files are renamed to: ---- desired output
but what the directory looks like currently after the script is run.
Maybe I typed something wrong, but I do get a log in the index directory. Thank you .
I have a bash that downloads a list and if that list has data in it then a new main directory is created (with the date) with several subdirectories (example1, example2, example3). My question is in that list there are portion of specific file types (.vcf.gz) - identifier towards the end that have... (0 Replies)
hi,
I am trying to get the FileType using the File command. I have one file, which holds Group separator along with ASCII character.
It's a Text file.
But when I ran the File command the FileType is coming as "data".
It should be "ASCII, Text file".
Is the latest version of File... (6 Replies)
Hi,
Here's my dilemma.
I need to replace the string Sept_2012 to Oct_2012 in all *config.py files within the current directory and below directories
Is this possible?
Also I am trying to find all instances of the string Sept_2012 within files in the current directory and below
I have... (13 Replies)
I have 84 files with the following names splitseqs.1, spliseqs.2 etc.
and I want to change the .number to a unique filename.
E.g.
change splitseqs.1 into splitseqs.7114_1#24
and
change spliseqs.2 into splitseqs.7067_2#4
So all the current file names are unique, so are the new file names.... (1 Reply)
I keep all my files on a NAS device and copy files from it to usb or local storage when needed. The bad part about this is that I often have the same file on numerous places. I'd like to write a script to check if the files in a given directory exist in another.
An example:
say I have a... (7 Replies)
I have an archive file that holds a batch of statements. I would like to be able to extract a certain statement based on the unique customer # (ie. 123456). The end for each statement is noted by "ENDSTM".
I can find the line number for the beginning of the statement section with sed.
... (5 Replies)
Ok, so I just got charged with the task of deleting some 300 user folders in a FTP server to free up some space. I managed to grep and cut the list of user folders to delete into a list of one user folder per line.
Example:
bob00
jane01
sue03
In the home folder, there are folders a-z, and... (5 Replies)
i All
I have scripting question.
I have a file "out.txt"
which is generated by another script
the file contains the following
my_identifier8859574
logout
The number is generated in the script and I have put the my_identifier bit in front of it as a unique identifier
I now have... (7 Replies)
Hi, I know that inode for each file is unique, but is it the for the directory? So far I found different directories has the same inode nubmer when you do ls -i, could some one explain why? Thanks a lot. (9 Replies)