I sincerely apologize for misleading you with my script. I paid too much attention to the code sample you provided in post #1 in this thread and not enough attention to the English description (which I found confusing). The description talks about copying files (and wasn't clear whether there was one file being copied or one file that contained the names of files to be copied), while your code was moving files whose source file names seemed to appear in one file and whose destination names seemed to appear in a second file. The fact that your code was moving (using mv) and not copying (using cp) seemed to confirm that there were three source files instead of one. (If there is only one source file, the last two copies will obviously fail since you're using mv instead of cp!)
If you have a single source file, and you're reading a destination name from a file, but you don't want the name of that destination file to be the name you read from the file; you need to clearly explain the transformation that is supposed to take place. (There is nothing in any of your code that makes any attempt to modify the names read from the file. And, I haven't found anything in your descriptions that talks about modifying the names found in the file other than confusing examples that don't clearly explain where the names are coming from.)
The code that you showed us (that you said produces no output) should be producing a diagnostic message because it is trying to invoke a utility named
continuing on until a matching double-quote character (") is found to match the double-quote character that appears at the end of $new_name". Note that the new_name variable is not defined in your modification to my code (and therefore, the expansion $new_name expands to an empty string).
Please give us a clearer description of what you are trying to do.
This User Gave Thanks to Don Cragun For This Post:
The metrics.txt in /home/cmccabe/Desktop/QC/test is the file that is copied 3 times. Each one of of those 3 copies is then renamed using lines 3,4,5 in analysis.txt in /home/cmccabe/Desktop/QC with a _ in the name.
So in /home/cmccabe/Desktop/QC/test before the code is executed there is one metrics.txt. Then after the code is executed there are 3 metrics.txt that are renamed using the analysis.txt, lines 3,4,5.
The format of analysis.txt is always the same, that is it is always five lines with the first two being skipped with lines 3,4,5 having the rename lines in them.
analysis.txt in /home/cmccabe/Desktop/QC
metrics.txt in /home/cmccabe/Desktop/QC/test, then code is executed:
desired output in /home/cmccabe/Desktop/QC/test
Does this help and thank you .
Last edited by cmccabe; 03-18-2017 at 11:55 AM..
Reason: fixed format
The metrics.txt in /home/cmccabe/Desktop/QC/test is the file that is copied 3 times. Each one of of those 3 copies is then renamed using lines 3,4,5 in analysis.txt in /home/cmccabe/Desktop/QC with a _ in the name.
So in /home/cmccabe/Desktop/QC/test before the code is executed there is one metrics.txt. Then after the code is executed there are 3 metrics.txt that are renamed using the analysis.txt, lines 3,4,5.
The format of analysis.txt is always the same, that is it is always five lines with the first two being skipped with lines 3,4,5 having the rename lines in them.
analysis.txt in /home/cmccabe/Desktop/QC
metrics.txt in /home/cmccabe/Desktop/QC/test, then code is executed:
desired output in /home/cmccabe/Desktop/QC/test
Does this help and thank you .
According to the above description, we are supposed to start with two files in a directory: metrics.txt and analysis.txt. Then we are supposed to create three more copies of metrics.txt also named metrics.txt and then we are supposed to rename three of those four file and end up with four files: 00-0000_Last-First_metrics.txt, 11-1111_LastName-FirstName_metrics.txt, 22-2222_LastLastName-FirstFirstName_metrics.txt, and analysis.txt.
Doing it in this sequence is impossible because you can never have two files in one directory with the same name. We can copy a file three times to new files with different names. But, if we do that, the original metrics.txt file would still be there. (But your description above says it should not be there.) So, is what you really want correctly described by saying that you want to rename metrics.txt to be the filename derives from the third line in analysis.txt and then you want to copy that file to two more files with filenames derived from the 4th and 5th lines in analysis.txt?
Why do you need three or four copies of the same text? Why not just link the three new names to metrics.txt using an ln command (or tell whatever program will be reading these files that the name of the file they should read is just metrics.txt)?
This User Gave Thanks to Don Cragun For This Post:
The metrics.txt in /home/cmccabe/Desktop/QC/test is saved as 3 separate .txt files. Each one of of those 3 .txt files is then renamed using lines 3,4,5 in analysis.txt in /home/cmccabe/Desktop/QC with a _ in the name.
Another process that is used is expecting 3 files in home/cmccabe/Desktop/QC/test to function properly, so this is a temporary solution to that (until that process can be re-written). Thank you very much .
home/cmccabe/Desktop/QC/test
analysis.txt in /home/cmccabe/Desktop/QC
desired output in home/cmccabe/Desktop/QC/test after the script executes
Since there is nothing to match between the two file I don't thin process substitution can be used, the names are just:
Last edited by cmccabe; 03-20-2017 at 09:11 AM..
Reason: fixed format
I have a specific set (all ending with .bam) of downloaded files in a directory /home/cmccabe/Desktop/NGS/API/2-15-2016. What I am trying to do is use a match to $2 in name to rename the downloaded files. To make things a more involved the date of the folder is unique and in the header of name... (1 Reply)
I have bunch of files in my source folder like below and every day based on date I am receiving file ex: Nov 28,Nov 29,Nov 30 ...
-rw-rw-r--+ 1 root root 20 Nov 27 06:00 aaaa27.txt
-rw-rw-r--+ 1 root root 20 Nov 28 06:00 aaaa28.txt
-rw-rw-r--+ 1 root root 20 Nov 29 06:00 aaaa29.txt
I... (4 Replies)
Hi All,
My requirement is as follows:
A file (say abc) will be having list of the .txt file names. I need to read this abc file line by line and rename the .txt file names inside it and move them to other folder/path.
Eg:
abc
-------
file1.txt
file2.txt
file3.txt
Output (should... (1 Reply)
Hi Guys,
I have the following problem. I have original file (org.txt) that looks like this
module v_1(.....)
//arbitrary number of text lines
endmodule
module v_2(....)
//arbitrary number of text lines
endmodule
module v_3(...)
//arbitrary number of text lines
endmodule
module... (6 Replies)
Hello,
I've been searching and reading, but I can't figure out how to solve this problem with my newbie skills.
In my directory, I have a list of files (see dirlist.txt attachment) that I need to merge and rename. I have part of the code of the code figured out (see below). However, I... (3 Replies)
Hi All,
I am very new to shell scripting .
In my current task i want to create .sh file that will rename the existing file with appending _bu in it. And then copy new file .
e.g if i have file linuxFirst.java then i want to rename it to linuxFirst_bu.java ..Then want replace with latest... (1 Reply)
hi all,
I have one config folder and updates folder.updates folder contains file tmp_2.0_20201208_45.xml and config folder contains file tmp.xml.When the tmp_2.0_20201208_45.xml file is copied in the config folder the name of this file is changed in config folder again as tmp.xml(old... (8 Replies)
Hi,
Found lots of stuff that is close but no cigar...
I have a file ie. a.txt, and I want to copy it to another directory 5000 times and call it:
a1.txt
a2.txt
...
a5000.txt
Struggling to put a loop together in this new world of AIX. please include full script for me to understand... (3 Replies)
File.jpg
I want to copy and rename this as 2008-12-02.jpg
I tried this copy File.jpg date '%y-%m-%d-%H:%M:%S'.jpg
This doesnt work.... what do i do? (1 Reply)
I'm looking to determine if I can use a grep command to read file and rename the file based on the first 3 characters of the data in the file.
An example is:
Read FileA
If the first 3 positions of the data in the file are "ITP", then rename the file as FileA_ITP, else if the first 3... (3 Replies)