Sponsored Content
Top Forums Shell Programming and Scripting Rename portion of file based on another file Post 302583092 by agama on Monday 19th of December 2011 02:15:44 PM
Old 12-19-2011
Actually, you can do this with a few changes to your script by building a translation list from your .txt file and using that to change the sequence number. I assume that CRC1 was to become ColonTrio1; wasn't quite sure based on your description.

Code:
typeset -A xlate            # must declare an associative array
while read old new          # build a translation list from old to new
do
    xlate[$old]=$new       # translation table
done <barcodekey.txt     # read in from your old to new translation file

find *gz | while IFS="_" read name lanename date sequence lane readpair number
do
    if [[ ! -f ColonTrio1_${xlate[$sequence]}}_${readpair}.fastq.gz ]] #merge and rename 
    then
        echo "cat *_${lanename}_*_${sequence}_*_${readpair}* >ColonTrio1_${xlate[$sequence]}}_${readpair}.fastq.gz"
    fi
done

I put the 'real' commands in an echo for testing -- it will print out what it would do without really doing it so you can validate before doing damage with the mv command etc. There will probably be many more commands echoed as multiple files found that generate the same merged file will test true in the if, where when running things for real the first file that results in a merge will supress additional files which were merged in. (Hope that makes sense)

Last edited by agama; 12-19-2011 at 03:22 PM.. Reason: typo -- clarification
 

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Select a portion of file based on query

Hi friends :) I am having a small problem and ur help is needed... I have a long file from which i want to select only some portions after filtering (grep). My file looks like : header xxyy lmno xxyy wxyz footer header abcd xy pqrs footer . . (14 Replies)
Discussion started by: vanand420
14 Replies

2. UNIX for Dummies Questions & Answers

Rename file based on first 3 characters of data in file

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)
Discussion started by: jchappel
3 Replies

3. Shell Programming and Scripting

mv command to rename multiple files that retain some portion of the original file nam

Well the title is not too good, so I will explain. I need to move (rename) files using a simple AIX script. ???file1.txt ???file2.txt ???file1a.txt ???file2a.txt to be: ???renamedfile1'date'.txt ???renamedfile2'date'.txt ???renamedfile1a'date'.txt ???renamedfile2a'date'.txt ... (4 Replies)
Discussion started by: grimace15
4 Replies

4. UNIX for Advanced & Expert Users

need to get a portion of entries in file based on a criteria --- Help please

All, Below is the file, what i need to do is take the text in between the /*-- and --*/ , i mean the jobs. Then i have grep for system name . If the job is there in system 1 i have to print to a file. Basically i want to take all the jobs that are in system1 to another file . because... (7 Replies)
Discussion started by: arunkumar_mca
7 Replies

5. Shell Programming and Scripting

Rename folder based on containing XML file

Hi everyone. I'm in need of a solution where i need to rename a folder to a name that's inside an XML file in that folder. OS is Ubuntu 9.10 with Gnome. I've tried using grep, sed and xpath, but can't seem to find a solution. This is the simplified folder structure: FOLDER-NAME -... (4 Replies)
Discussion started by: CoolCow
4 Replies

6. Shell Programming and Scripting

Need to rename file based on name in same file

Good day. I need a one-liner (if possible) otherwise a longer script to do the following: I have a list of files in a directory with the same filename extension, ie. firstfile.cks, anotherfile.cks, somefile.cks, etc.The filename and extension, however, are incorrect. The correct filename... (7 Replies)
Discussion started by: BRH
7 Replies

7. Shell Programming and Scripting

Remove or rename based on contents of file

I am trying to use the two files shown below to either remove or rename contents in one of those files. If in file1.txt $5 matches $5 of file2.txt and the value in $1 of file1.txt is not "No Match" then that value is substituted for all values in $5 and $1 of file2.txt. If however in $1 ... (5 Replies)
Discussion started by: cmccabe
5 Replies

8. Shell Programming and Scripting

Rename files based on name in text file

Hello, I have a text file "file.list" with the contents below. file1 filename1 file2 filename2 file3 filename3 file1, file2 and file3 are files existing in the same directory as the text file file.list. I want to rename file1 to filename1, file2 to filename2, as show in the text... (1 Reply)
Discussion started by: james2009
1 Replies

9. Shell Programming and Scripting

Bash to copy file 3 times and rename based on another file

In the below bash I am trying to copy the only text file (always only one) in /home/cmccabe/Desktop/list/QC/metrics.txt and rename each of the 3 text files according to /home/cmccabe/Desktop/test/list.txt using lines 3, 4 ,5. This format (that is list.txt) is always 5 lines. Thank you :). ... (12 Replies)
Discussion started by: cmccabe
12 Replies

10. Shell Programming and Scripting

Bash to rename portion of file using match to another

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)
Discussion started by: cmccabe
3 Replies
XtParseTranslationTable(3)					   XT FUNCTIONS 					XtParseTranslationTable(3)

NAME
XtParseTranslationTable, XtAugmentTranslations, XtOverrideTranslations, XtUninstallTranslations - manage translation tables SYNTAX
XtTranslations XtParseTranslationTable(String table); void XtAugmentTranslations(Widget w, XtTranslations translations); void XtOverrideTranslations(Widget w, XtTranslations translations); void XtUninstallTranslations(Widget w); ARGUMENTS
table Specifies the translation table to compile. translations Specifies the compiled translation table to merge in (must not be NULL). w Specifies the widget into which the new translations are to be merged or removed. DESCRIPTION
The XtParseTranslationTable function compiles the translation table into the opaque internal representation of type XtTranslations. Note that if an empty translation table is required for any purpose, one can be obtained by calling XtParseTranslationTable and passing an empty string. The XtAugmentTranslations function nondestructively merges the new translations into the existing widget translations. If the new transla- tions contain an event or event sequence that already exists in the widget's translations, the new translation is ignored. The XtOverrideTranslations function destructively merges the new translations into the existing widget translations. If the new transla- tions contain an event or event sequence that already exists in the widget's translations, the new translation is merged in and override the widget's translation. To replace a widget's translations completely, use XtSetValues on the XtNtranslations resource and specify a compiled translation table as the value. The XtUninstallTranslations function causes the entire translation table for widget to be removed. SEE ALSO
XtAppAddActions(3), XtCreatePopupShell(3), XtParseAcceleratorTable(3), XtPopup(3) X Toolkit Intrinsics - C Language Interface Xlib - C Language X Interface X Version 11 libXt 1.1.4 XtParseTranslationTable(3)
All times are GMT -4. The time now is 04:11 AM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy