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
CUDA Runtime API Specific Functions(3)			     Hardware Locality (hwloc)			    CUDA Runtime API Specific Functions(3)

NAME
CUDA Runtime API Specific Functions - Functions static inline int hwloc_cudart_get_device_pci_ids (hwloc_topology_t topology , int idx, int *domain, int *bus, int *dev) static inline int hwloc_cudart_get_device_cpuset (hwloc_topology_t topology , int idx, hwloc_cpuset_t set) static inline hwloc_obj_t hwloc_cudart_get_device_pcidev (hwloc_topology_t topology, int idx) static inline hwloc_obj_t hwloc_cudart_get_device_osdev_by_index (hwloc_topology_t topology, unsigned idx) Detailed Description Function Documentation static inline int hwloc_cudart_get_device_cpuset (hwloc_topology_t topology, intidx, hwloc_cpuset_tset) [static] Get the CPU set of logical processors that are physically close to device idx. Return the CPU set describing the locality of the CUDA device whose index is idx. Topology topology and device idx must match the local machine. I/O devices detection and the CUDA component are not needed in the topology. The function only returns the locality of the device. If more information about the device is needed, OS objects should be used instead, see hwloc_cudart_get_device_osdev_by_index(). This function is currently only implemented in a meaningful way for Linux; other systems will simply get a full cpuset. static inline hwloc_obj_t hwloc_cudart_get_device_osdev_by_index (hwloc_topology_ttopology, unsignedidx) [static] Get the hwloc OS device object corresponding to the CUDA device whose index is idx. Return the OS device object describing the CUDA device whose index is idx. Return NULL if there is none. The topology topology does not necessarily have to match the current machine. For instance the topology may be an XML import of a remote host. I/O devices detection and the CUDA component must be enabled in the topology. If not, the locality of the object may still be found using hwloc_cudart_get_device_cpuset(). Note: The corresponding PCI device object can be obtained by looking at the OS device parent object. This function is identical to hwloc_cuda_get_device_osdev_by_index(). static inline int hwloc_cudart_get_device_pci_ids (hwloc_topology_t topology, intidx, int *domain, int *bus, int *dev) [static] Return the domain, bus and device IDs of the CUDA device whose index is idx. Device index idx must match the local machine. static inline hwloc_obj_t hwloc_cudart_get_device_pcidev (hwloc_topology_ttopology, intidx) [static] Get the hwloc PCI device object corresponding to the CUDA device whose index is idx. Return the PCI device object describing the CUDA device whose index is idx. Return NULL if there is none. Topology topology and device idx must match the local machine. I/O devices detection must be enabled in topology topology. The CUDA component is not needed in the topology. Author Generated automatically by Doxygen for Hardware Locality (hwloc) from the source code. Version 1.7 Sun Apr 7 2013 CUDA Runtime API Specific Functions(3)
All times are GMT -4. The time now is 11:27 PM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy