Sponsored Content
Top Forums Shell Programming and Scripting Read Field from file1 and find and replace in file2 Post 302511417 by Chubler_XL on Wednesday 6th of April 2011 06:28:12 PM
Old 04-06-2011
Not real clear what you are after here. Some sssumptions I've made:

1. The order the files are output should remain the same as defined in config file
2. Multiple replaces may appear for each file
3. Replace tag (eg @Phone@) may have different values for different files

Here is the solution in awk:

Code:
awk -F\| '{if(!($1 in F))P[++f]=$1;F[$1];R[$1,$2]=$3}
END{
   for(i=1;i<=f;i++)  {
     while((getline < P[i]) > 0) {
         for(idx in R) {
            split(idx,val,SUBSEP);
            if(val[1]==P[i]) gsub(val[2],R[idx]);
         }
         print $0
     }
     close(P[i])
   }
}' ConfigFile


Last edited by Chubler_XL; 04-06-2011 at 07:35 PM..
This User Gave Thanks to Chubler_XL For This Post:
 

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Read each word from File1 and search each file in file2

file1: has all words to be searched. 100007 200999 299997 File2: has all file names to be searched. C:\search1.txt C:\search2.txt C:\search3.txt C:\search4.txt Outfile: should have all found lines. Logic: Read each word in file1 and search each file in the list of File2; if the... (8 Replies)
Discussion started by: clem2610
8 Replies

2. Shell Programming and Scripting

AWK: Pattern match between 2 files, then compare a field in file1 as > or < field in file2

First, thanks for the help in previous posts... couldn't have gotten where I am now without it! So here is what I have, I use AWK to match $1 and $2 as 1 string in file1 to $1 and $2 as 1 string in file2. Now I'm wondering if I can extend this AWK command to incorporate the following: If $1... (4 Replies)
Discussion started by: right_coaster
4 Replies

3. Shell Programming and Scripting

using field 2 in file2 to complete field 3 in file1

Hello, I was hoping someone could help me with this work related problem... basically what I want to do is the following: file2: 1 o 2 t 4 f 5 v 7 n 8 e 10 a file1: 1 : (8 Replies)
Discussion started by: smarones
8 Replies

4. Shell Programming and Scripting

search from file1 and replace into file2

I have 2 files: file1.txt: 1|15|XXXXXX||9630716||0096000||30/04/2012|E|O|X||||20120525135617-30.04.2012|PAT66OLM|STA||||00001|STA_0096000_YYYPPPXTMEX00_20120525135617_02_P.pdf|... (2 Replies)
Discussion started by: pparthiv
2 Replies

5. UNIX for Dummies Questions & Answers

if matching strings in file1 and file2, add column from file1 to file2

I have very limited coding skills but I'm wondering if someone could help me with this. There are many threads about matching strings in two files, but I have no idea how to add a column from one file to another based on a matching string. I'm looking to match column1 in file1 to the number... (3 Replies)
Discussion started by: pathunkathunk
3 Replies

6. Shell Programming and Scripting

Retreive the records from file2 by using the first field in file1

Hi Freinds, i have a file1 as below file1 1|ndmf|fdd|d3484|34874 2|jdehf|wru7|478|w489 3|dfkj|wej|484|49894 file2 contains lakhs of records and not in sorted order i want to retrive only the records from file2 by searcing the first field of file 1 i used grep ^1 file2... (4 Replies)
Discussion started by: i150371485
4 Replies

7. Shell Programming and Scripting

Replacing first field of file2 with the second filed of file1 for matching cases

Dear All, Need your help..:D I am not regular on shell scripts..:( I have 2 files.. Content of file1 cellRef 4};"4038_2_MTNL_KALAMBOLI" cellRef 1020};"4112_3_RAINBOW_BLDG" cellRef 134};"4049_2_TATA_HOSPITAL" cellRef 1003};"4242_3_HITESH_CONSTRUCTION" cellRef... (6 Replies)
Discussion started by: ailnilanjan
6 Replies

8. Shell Programming and Scripting

awk to search field2 in file2 using range of fields file1 and using match to another field in file1

I am trying to use awk to find all the $2 values in file2 which is ~30MB and tab-delimited, that are between $2 and $3 in file1 which is ~2GB and tab-delimited. I have just found out that I need to use $1 and $2 and $3 from file1 and $1 and $2of file2 must match $1 of file1 and be in the range... (6 Replies)
Discussion started by: cmccabe
6 Replies

9. Shell Programming and Scripting

awk to update field in file2 if not the same as file1

Trying to use awk to: update $2 in file2 with the $2 value in file1, if $1 in file1 matches $13 in file2, which is tab-delimeted. The $2values may already be the same so in that case nothing happens and the next line is processed. There are exactly 4,605 unique $13 values. Thank you :). ... (4 Replies)
Discussion started by: cmccabe
4 Replies

10. Shell Programming and Scripting

awk to update field using matching value in file1 and substring in field in file2

In the awk below I am trying to set/update the value of $14 in file2 in bold, using the matching NM_ in $12 or $9 in file2 with the NM_ in $2 of file1. The lengths of $9 and $12 can be variable but what is consistent is the start pattern will always be NM_ and the end pattern is always ;... (2 Replies)
Discussion started by: cmccabe
2 Replies
WSCONS.CONF(5)						      BSD File Formats Manual						    WSCONS.CONF(5)

NAME
wscons.conf -- workstation console config file SYNOPSIS
wscons.conf DESCRIPTION
The wscons.conf file defines parameters regarding to the workstation console (wscons). The file consists of lines starting with a keyword, and one or more arguments. Empty lines and lines starting with a hash (``#'') are ignored. This configuration file is used by the /etc/rc.d/wscons script which parses /etc/wscons.conf and runs wsconscfg(8), wsconsctl(8), and/or wsfontload(8) as configured. See rc.conf(5) for details on enabling the rc.d script. The following keywords and arguments are recognized: font name width height enc file Used to load a font via wsfontload(8). name gives a font name that can be used later, width can be used to specify the width of a font character in pixel, height is the same, just for the font characters' height. enc is used to declare the font's encoding, see the description on wsfontload(8)'s -e option for more detail. file gives the absolute path to the font file. See wsfontload(8) for more information. screen idx scr emul Add and configure virtual console number idx using a screen type of scr (e.g. 80x25) and a emul terminal emulation (e.g. vt100). See wsconscfg(8) for further parameter description. keyboard kbd Attach and configure keyboard kbd using ``wsconscfg -k''. If kbd is '-' or 'auto', the first free keyboard will be used. See wsconscfg(8) for more information. encoding enc Set the keyboard map to the given language code enc, using ``wsconsctl -w encoding=enc''. The map must be supported by the key- board driver in use and must be compiled into the kernel. See the keyboard driver's manpage (e.g., pckbd(4), ukbd(4)) for details. mapfile file Parses the contents of file, which contains a keyboard map per line, and calls ``wsconsctl -w map+='' for each line. See wsconsctl(8) for details. mux idx Used to attach and configure keyboard/mouse multiplexors, using ``wsconscfg -m idx''. See wsconscfg(8) for more information. setvar dev var val Set arbitrary wscons variable var to value val for specified control device dev. Can be used for direct modification of wscons(4) variables, when no other keywords are suitable. See wsconsctl(8) for more information. Command arguments can be specified as ``-'' which makes default values come into effect as described in the documentation of the utilities. FILES
/etc/wscons.conf SEE ALSO
wscons(4), wsconscfg(8), wsconsctl(8), wsfontload(8) BSD
November 22, 2008 BSD
All times are GMT -4. The time now is 01:36 PM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy