Bash to add portion of text to files in directory using numerical match
In the below bash I am trying to rename eachof the 3 text files in /home/cmccabe/Desktop/percent by matching the numerical portion of each file to lines 3,4, or 5 in /home/cmccabe/Desktop/analysis.txt. There will always be a match between the files. When a match is found each text file in /home/cmccabe/Desktop/percent is renamed adding the textafter the _ (underscore) in /home/cmccabe/Desktop/analysis.txt to each line.
text file in /home/cmccabe/Desktop/percent - there could be a maximum of 3 files in this directory
text file in /home/cmccabe/QC/analysis.txt
desired result in /home/cmccabe/QC/percent
The set -x shows that the files are renamed correctly but they are not moved to /home/cmccabe/Desktop/percent. Currently the 3 text files in there are the same as above (without the name added to them).
set -x
Description of what I think is going on (I will try to include these:
bash
I am not sure why the mv is working and the 3 text files remain the same. The echo shows them renamed correctly. Thank you .
Last edited by cmccabe; 04-02-2017 at 11:33 AM..
Reason: fixed format
Take a look at your code again. There is no mv command in your code; only an echo command. If the echo shows that your script is correctly determining what arguments should be passed to mv, what happens if you change the line:
in your code to:
(i.e., remove the echo and the backslashes)?
This User Gave Thanks to Don Cragun For This Post:
That fixed it, but now I have the same problem I did before. The bash, as is works great as long as all 3 files are in the directory /home/cmccabe/QC/percent.
Since I run a process on each file, after it gets renamed it is moved to the directory. When the next filename gets renamed, the other one gets duplicated. If there is a third the first filename repeats 3 times the second filename duplicated and third is fine.
So if in /home/cmccabe/QC/percent
code executes a second time:
code executes a third time:
Maybe I just need to only execute the command once after all 3 files are in the directory? If a file is in the directory already it has been renamed already but I'm not sure how to prevent the duplication. Thank you .
In the portion of bash below I am using rename to match the $id variable to $file and when a match (there will alwsys be one) is found then the $id is removed from each bam and bam.bai in $file and _test is added to thee file name before the extension. Each of the variables is set correctly but... (3 Replies)
I am trying to mv each of the .vcf files in the variants folder to the folder in /home/cmccabe/f2 that the .vcf id is found in file. $2 in file will always have the id of a .vcf in the variants folder. The line in blue staring with R_2019 in file up to the -v5.6 will always be an exact match to a... (4 Replies)
In the bash below the unique headers of each vcf.gz are stored in a text file with the same name. That is if 16-0000-file.vcf.gz was used the header text file would be 16-0000-file_header.txt.
There can be multiple vcf.gz in a directory, usually 3, that I need to fix the header in each file before... (6 Replies)
The below bash connects to a site, downloads a file, searches that file based of user input - could be multiple (all that seems to work). What I am not able to figure out is how to display on the screen match found or no match found" and write a file to a directory (C:\Users\cmccabe\Desktop\wget)... (4 Replies)
Trying to match the text from file1 to file2 and print what matches in a new file (match.txt) and what does not in another (missing.txt).
awk -F'|' 'NR==FNR{c++;next};c > 0' flugent.txt IDT.txt > match.txt
Thank you :). (8 Replies)
Hi all,
What I would like to achieve is to batch change the code below in every pdf in a given directory (each pdf is uncompressed so that can be easily edited).
An example of the javascript code:
if (this.hostContainer) { try { this.hostContainer.postMessage(pp_216', 15259]);... (3 Replies)
Dear all,
I have a specific problem that I don't quite understand how to solve. I have two files, both of the same format:
XXXXXX_FIND1 bla bla bla
bla
bla
bla
bla
bla
bla
bla
bla
bla
========
(return)
XXXXXX_FIND2 bla bla bla
bla
bla
bla (10 Replies)
I have searched the internet (including these forums) and perhaps I'm not using the right wording.
What I'm looking for is a function (preferably C) that analyzes the similitude of two numerical or near-numerical values, and returns either a true/false (match/nomatch) or a return code that... (4 Replies)
I have 20 files in a direcotry like BARE01_DLY_MKT_YYYYMMDD. The MKT differes for all these files but the remaining syntax remains the same for a particular day. If I am checking for today I need to make sure that there are 20 files that start with BARE01_DLY_MKT_20060720. How can I write a... (31 Replies)
hi,
I have a script which accept filename and process them, however, one of the file needs 'special' handling so I need to identify it, say the filename contains the word "STOCK" (i.e. NEWYORKSTOCKLIST20060627.txt), I want to check if the filename contains the word "STOCK", how can I do that?... (1 Reply)