Sponsored Content
Full Discussion: Multiple replacement
Top Forums UNIX for Dummies Questions & Answers Multiple replacement Post 302814715 by Don Cragun on Thursday 30th of May 2013 05:59:31 AM
Old 05-30-2013
Another way to do this using awk once instead of using sed once for each line in the equivalences file is:
Code:
awk '
BEGIN { OFS = "\t"}
FNR == NR {ID[$1] = $2;next}
{       if(FNR == 1) sub(/ID/, ID["ID"])
        else if($6 in ID) $6 = ID[$6]
        print
}' equivalences target

If you're using a Solaris/SunOS system, use /usr/xpg4/bin/awk, /usr/xpg6/bin/awk, or nawk instead of awk.

For the input files shown in the 1st message in this thread, the output produced is:
Code:
Start (bp)       End (bp)  Strand       Rank    Gene            RefSeq             Chromosome
51066374        51066598        -1      1       ARSA    NM_001085426    22
51063446        51063892        -1      8       ARSA    NM_000487       22
51064007        51064109        -1      8       ARSA    ENST00000395621 22
51063457        51063892        -1      8       ARSA    NM_001085428    22

This User Gave Thanks to Don Cragun For This Post:
 

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

String replacement in multiple files

What is the most simple way to search multiple text files in multiple directories for a string then replace it with another string? I have about 300 files that I need to update and I'm just looking for alternatives rather than having to edit each one by hand. Thanks in advance! (2 Replies)
Discussion started by: WABonnett
2 Replies

2. UNIX for Dummies Questions & Answers

Regarding Replacement

I have two files: file1: somedata <html> <head> This is sample statement ...... ...... </head> </html> somedata file2: olga 81 91 B A rene 82 92 B A zack 83 93 Expextd Result: (2 Replies)
Discussion started by: rajx
2 Replies

3. Shell Programming and Scripting

sed xml file multiple line replacement

I have a file called config.xml, it's a simple xml file, and I need use sed/awk to erase some lines. <machine xsi:type="unix-machineType"> <name>server1</name> <node-manager> <name>server1</name> <listen-address>server1</listen-address> </node-manager> ... (3 Replies)
Discussion started by: cbo0485
3 Replies

4. Shell Programming and Scripting

Multiple String with a number replacement and more..

Hello all, First of all, I could not made up a nice title what explains my problem in short,sorry for that already. I have the next file which contains the following, CREATE:ENTRY:\ DNAME,"referenceId=sondakika30,referenceId=User1,\ referenceId=Company,\ ... (2 Replies)
Discussion started by: sondakika
2 Replies

5. Shell Programming and Scripting

help me :replacement

Hi pls help me for below; i have a file .content is : =================== uid,pcsPricingPlan,refPcsQosProfName 821910002022,smartlimit,SGSNQOS1 i have to replace the value of uid and pricingplan by a unix script. may be the value would be next line or any where in the file. pls... (9 Replies)
Discussion started by: Aditya.Gurgaon
9 Replies

6. UNIX for Dummies Questions & Answers

replacement

my filename.txt looks like this: 2079951061790 SCK0000891539000000000000021600R 2079951061790 SCK0000901487000000000000028900R 2079951061790 SCK0000903092000000000000021300R 2079951074758 ... (9 Replies)
Discussion started by: tjmannonline
9 Replies

7. Shell Programming and Scripting

Grep from multiple patterns multiple file multiple output

Hi, I want to grep multiple patterns from multiple files and save to multiple outputs. As of now its outputting all to the same file when I use this command. Input : 108 files to check for 390 patterns to check for. output I need to 108 files with the searched patterns. Xargs -I {} grep... (3 Replies)
Discussion started by: Diya123
3 Replies

8. UNIX for Beginners Questions & Answers

GUI for multiple pattern replacement

I'm trying to change a few programs in our environment. Basically We have hardcoded some server names and stuff, So I want some one to suggest me some UNIX gui tools that can be used to replace these.. I really don't want to deal doing this through the command line. I want to transfer the files... (3 Replies)
Discussion started by: sudden
3 Replies

9. Shell Programming and Scripting

Multiple Replacement in a Text File in one operation (sed/awk) ?

Hi all, Saying we have two files: 1. A "Reference File" whose content is "Variable Name": "Variable Value" 2. A "Model File" whose content is a model program in which I want to substitute "VariableName" with their respective value to produce a third file "Program File" which would be a... (4 Replies)
Discussion started by: dae
4 Replies

10. Solaris

Is this MB, which needs replacement ?

Hello, I am getting below error in fmadm output. This server is not in support, so can't reach them. Is it showing that motherboard is faulty and should be replaced ? It was rebooted a week back and then, there were no errors # fmadm faulty --------------- ------------------------------------ ... (1 Reply)
Discussion started by: solaris_1977
1 Replies
PSPELL_CONFIG_SAVE_REPL(3)						 1						PSPELL_CONFIG_SAVE_REPL(3)

pspell_config_save_repl - Determine whether to save a replacement pairs list along with the wordlist

SYNOPSIS
bool pspell_config_save_repl (int $dictionary_link, bool $flag) DESCRIPTION
pspell_config_save_repl(3) determines whether pspell_save_wordlist(3) will save the replacement pairs along with the wordlist. Usually there is no need to use this function because if pspell_config_repl(3) is used, the replacement pairs will be saved by pspell_save_wordlist(3) anyway, and if it is not, the replacement pairs will not be saved. pspell_config_save_repl(3) should be used on a config before calling pspell_new_config(3). PARAMETERS
o $dictionary_link - o $flag - TRUE if replacement pairs should be saved, FALSE otherwise. RETURN VALUES
Returns TRUE on success or FALSE on failure. NOTES
Note This function will not work unless you have pspell .11.2 and aspell .32.5 or later. PHP Documentation Group PSPELL_CONFIG_SAVE_REPL(3)
All times are GMT -4. The time now is 09:06 AM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy