Sponsored Content
Top Forums UNIX for Beginners Questions & Answers How to replace matching words defined in one file on another file? Post 303036148 by Scrutinizer on Sunday 16th of June 2019 05:30:29 AM
Old 06-16-2019
Yes that is correct, #3 uses exact strings, so it correctly identifies the right field, and the sub() in itself isn't the problem either, since iteration occurs over the fields and not over the key value pairs (therefore it can substititute multiple occurrences on one line), but the problem is in the replacement part, it was attempting to use sub() on the record instead of a direct assignment to the field, to avoid losing the file separators.

This adaptation should fix that:
Code:
awk '
  NR==FNR {
    A[$1]=$2
    next
  } 
  {
    for(i=1; i<=NF; i++) {
      n=split($i, F, /[(,]/)
      org=F[n]
      if(org in A)
        sub(org, A[org], $i)
    } 
    print
  }
'  FS="=" file2 FS=/ OFS=/ file1


Last edited by Scrutinizer; 06-16-2019 at 06:37 AM..
This User Gave Thanks to Scrutinizer For This Post:
 

10 More Discussions You Might Find Interesting

1. Programming

getting file words as pattern matching

Sir, I want to check for the repation of a user address in a file i used || as my delimiter and want to check repetaip0n of the address that is mailid and then i have to use IMAP and all. How can i do this... I am in linux ...and my file is linux file. ... (5 Replies)
Discussion started by: arunkumar_mca
5 Replies

2. Shell Programming and Scripting

replace words in file based on another file

Hello, Can someone kindy help me solve this problem..I am using SunOS shell script I got a file A with following content: This is my correct document. I wrote 111 This is my incorrect word , 222 This is my wrong statement 333 This is my correct document 444 This is my correct document 555... (9 Replies)
Discussion started by: kinmak
9 Replies

3. UNIX for Dummies Questions & Answers

sed replace words in file and keep some

lets see if i can explain this in a good way. im trying to replace some words in a file but i need to know what the words are that is beeing replaced. not sure if sed can do this. file.name.something.1DATA01.something.whatever sed "s/./.DATA?????/g" need to know what the first . is... (2 Replies)
Discussion started by: cas
2 Replies

4. Shell Programming and Scripting

How to from grep command from a file which contains matching words?

Hi all I have a file with below content (content is variable whenever new product is launched). I need form a grep command like this egrep "Unknown product|Invalid symboland so on" How to do it using a script? Unknown product Invalid symbol No ILX exch found exceeds maximum size AFX... (4 Replies)
Discussion started by: johnl
4 Replies

5. Shell Programming and Scripting

search the pattern in a file and replace with variable already defined previously in csh

I want to replace a certain pattern with the variable already defined. e.g. set path_verilog = /home/priya/bin/verilogfile my file contents are : verilog new verilog is defined here verilog_path_comes I am using the below command sed 's/verilog_path_comes/'$path_verilog'/g' <filename>... (2 Replies)
Discussion started by: nehashine
2 Replies

6. Shell Programming and Scripting

Replace text in column1 of a file matching columns of another file

Hi all, I have 2 files: species-names.txt Abaca-bunchy-top-virus ((((Abaca-bunchy-top-virus((Babuvirus((Unassigned((Nanoviridae((Unassigned)))) Abutilon-mosaic-virus ((((Abutilon-mosaic-virus((Begomovirus((Unassigned((Geminiviridae((Unassigned))))... (2 Replies)
Discussion started by: thienxho
2 Replies

7. UNIX for Dummies Questions & Answers

Replace the words in the file to the words that user type?

Hello, I would like to change my setting in a file to the setting that user input. For example, by default it is ONBOOT=ON When user key in "YES", it would be ONBOOT=YES -------------- This code only adds in the entire user input, but didn't replace it. How do i go about... (5 Replies)
Discussion started by: malfolozy
5 Replies

8. Shell Programming and Scripting

How to replace words in file?

Hi Guys, I have a text where we used Ram in 10 times now I want replace all Ram words by Shyam word then how to do it. (6 Replies)
Discussion started by: aaditya321
6 Replies

9. Shell Programming and Scripting

How to replace some specific words from file?

I have the file like this. cat 123.txt <p> <table border='1' width='90%' align='center' summary='Script output'> <tr><td>text </td> </tr> </table> </p> I want to replace some tags and want the output like below. I tried with awk & sed commands. But no luck. Could someone help me on this? ... (4 Replies)
Discussion started by: thomasraj87
4 Replies

10. Shell Programming and Scripting

Replace particular words in file based on if finds another words in that line

Hi All, I need one help to replace particular words in file based on if finds another words in that file . i.e. my self is peter@king. i am staying at north sydney. we all are peter@king. How to replace peter to sham if it finds @king in any line of that file. Please help me... (8 Replies)
Discussion started by: Rajib Podder
8 Replies
captoinfo(1M)															     captoinfo(1M)

NAME
captoinfo - convert a termcap description into a terminfo description SYNOPSIS
n] [filenames] DESCRIPTION
looks in filenames for termcap(3X) descriptions. For each one found, an equivalent terminfo(4) description is written to standard output along with any comments found. The short two letter name at the beginning of the list of names in a entry, a holdover from Version 6 UNIX, is removed. Any description that is expressed relative to another description (as specified in the tc= field) is reduced to the minimum superset before output. If no filename is given, the environment variable is used for the filename or entry. If is a full pathname to a file, only the terminal whose name is specified in the environment variable is extracted from that file. If the environment variable is not set, the file is read. Options captoinfo recognizes the following options: Print one field per line. If this option is not selected, multiple fields are printed on each line up to a maximum width of 60 characters. Print (verbose) tracing information as the program runs. Additional options print more information (for example or Change the output width to n characters. DIAGNOSTICS
The termcap entry is not valid. In particular, check for an invalid 'tc=' entry. The termcap description had an entry for 'cc' whose type was not boolean, numeric or string. The boolean termcap entry 'cc' was entered as a numeric or string capability. An unknown termcap code was specified. The terminal type specified could not be found in the termcap file. The termcap code was specified as a null string. The correct way to cancel an entry is with an as in Giving a null string could cause incorrect assumptions to be made by any software that uses termcap or terminfo. When parsing the 'ko' capability, the key 'cc' was specified as having the same value as the capability 'cc', but the key 'cc' already had a value assigned to it. A key that could not be handled was specified in the 'ko' capability. The 'ma' capability specified a function key with a value different from that specified in another setting of the same key. A vi key unknown to captoinfo was specified in the 'ma' capability. assumes that the sg (now xmc) and ug values were the same. The parameterized string being created should be rewritten by hand. The terminal type was null. This occurs when is null or not set. The specified file could not be opened. This termcap capability is no longer supported in terminfo, and therefore cannot be translated. WARNINGS
Certain defaults are assumed to be true. For example, the bell character bel) is assumed to be The linefeed capability nl) is assumed to be the same for both and cud1 and ind, respectively). Padding information is assumed to belong at the end of the string. The algorithm used to expand parameterized information for fields such as cm, cup) sometimes produces a string which, though technically correct, may not be optimal. In particular, the rarely used operation produces strings that are especially long. Most occurrences of these less than optimal strings are flagged with a warning message, and may need to be recoded by hand. HP supports only terminals listed on the current list of supported devices. However, the terminfo database contains both supported and nonsupported terminals. If you use nonsupported terminals, they may not work correctly. AUTHOR
was developed by AT&T. SEE ALSO
tic(1M), untic(1M), termcap(3X), terminfo(4), infocmp(1M). captoinfo(1M)
All times are GMT -4. The time now is 03:03 AM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy