Sponsored Content
Top Forums Shell Programming and Scripting Replacing first field of file2 with the second filed of file1 for matching cases Post 302924050 by Don Cragun on Thursday 6th of November 2014 03:52:15 AM
Old 11-06-2014
You could try something like:
Code:
awk '
BEGIN {	FS = OFS = ";"
}
FNR == NR {
	x[$1] = $2
	next
}
$1 in x {
	$2 = x[$1]
}
1' file[12]

which (with your sample files) produces the output:
Code:
cellRef 2530};disabled;main;0;"Trx4";
 cellRef 2530};"4015_3_DRONAGIRI";main;0;"Trx2";
 cellRef 2355};"4245_3_SAI_PRASAD_KOPRA";main;12;"Trx3";outer
 cellRef 765};"4116_3_MARUTI_TOWER";main;11;"Trx2";
 cellRef 580};"4344_1_CHAMUNDA_DARSHAN";secondary;0;"Trx5";inner
 cellRef 580};"4344_1_CHAMUNDA_DARSHAN";secondary;0;"Trx6";inner
 cellRef 2437};"4600_1_YOGESHWAR_CHS";main;-1;"Trx1";
 cellRef 2437};"4600_1_YOGESHWAR_CHS";main;-1;"Trx3";
 cellRef 2437};"4600_1_YOGESHWAR_CHS";main;-1;"Trx2";
 cellRef 2437};"4600_1_YOGESHWAR_CHS";main;-1;"Trx4";
 cellRef 2475};"4136_2_MTNL_APMC";main;6;"Trx3";outer
 cellRef 2305};disabled;main;6;"Trx2";
 cellRef 2368};disabled;main;0;"Trx4";outer
 cellRef 2368};disabled;secondary;0;"Trx5";inner
 cellRef 2368};disabled;secondary;0;"Trx6";inner
 cellRef 956};disabled;secondary;4;"Trx5";inner
 cellRef 956};disabled;secondary;3;"Trx6";inner
 cellRef 932};disabled;secondary;6;"Trx5";inner
 cellRef 932};disabled;secondary;5;"Trx6";inner
 cellRef 864};disabled;secondary;4;"Trx5";inner

Note that no change is made to the first line because there is a big difference between:
Code:
cellRef<space>2530}
        and
<space>cellRef<space>2530}

If you want to try this on a Solaris/SunOS system, change awk to /usr/xpg4/bin/awk, /usr/xpg6/bin/awk, or nawk.
This User Gave Thanks to Don Cragun For This Post:
 

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

replacing text in file1 with list from file2

I am trying to automate a process of searching through a set of files and replace all occurrences of a formatted text with the next item in the list of a second file. Basically i need to replace all instances of T????CLK???? with an IP address from a list in a second file. the second file is one IP... (9 Replies)
Discussion started by: dovetail
9 Replies

2. Shell Programming and Scripting

awk - replacing stings in file1 with column1 in file2

Hello, I've never used awk before, but from what I've read, it will best suit what I'm trying to do. I have 2 files. I need to replace strings in file1 with the first column of a matching string in file2. Below are examples: File1: random-string1 1112 1232 3213 2131 random-string2... (7 Replies)
Discussion started by: upstate_boy
7 Replies

3. 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

4. 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

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

Pattern Matching & replacing of content in file1 with file2

I have file 1 & file 2 with content mentioned below. I want to get the output as shown in file3. Requirement: check the content of column 1 & column 2, if value of column 1 in file1 matches with first column of file2 then remaining columns(2&3) of file2 should get replaced, also if value of... (4 Replies)
Discussion started by: siramitsharma
4 Replies

7. Shell Programming and Scripting

Compare file1 for matching line in file2 and print the difference in matching lines

Hello, I have two files file 1 and file 2 each having result of a query on certain database tables and need to compare for Col1 in file1 with Col3 in file2, compare Col2 with Col4 and output the value of Col1 from File1 which is a) not present in Col3 of File2 b) value of Col2 is different from... (2 Replies)
Discussion started by: RasB15
2 Replies

8. UNIX for Dummies Questions & Answers

Compare file1 and file2, print matching lines in same order as file1

I want to print only the lines in file2 that match file1, in the same order as they appear in file 1 file1 file2 desired output: I'm getting the lines to match awk 'FNR==NR {a++}; FNR!=NR && a' file1 file2 but they are in sorted order, which is not what I want: Can anyone... (4 Replies)
Discussion started by: pathunkathunk
4 Replies

9. 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

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
POSTMULTI(1)						      General Commands Manual						      POSTMULTI(1)

NAME
postmulti - Postfix multi-instance manager SYNOPSIS
ENABLING MULTI-INSTANCE MANAGEMENT: postmulti -e init [-v] ITERATOR MODE: postmulti -l [-aRv] [-g group] [-i name] postmulti -p [-av] [-g group] [-i name] command... postmulti -x [-aRv] [-g group] [-i name] command... LIFE-CYCLE MANAGEMENT: postmulti -e create [-av] [-g group] [-i name] [-G group] [-I name] [param=value ...] postmulti -e import [-av] [-g group] [-i name] [-G group] [-I name] [config_directory=/path] postmulti -e destroy [-v] -i name postmulti -e deport [-v] -i name postmulti -e enable [-v] -i name postmulti -e disable [-v] -i name postmulti -e assign [-v] -i name [-I name] [-G group] DESCRIPTION
The postmulti(1) command allows a Postfix administrator to manage multiple Postfix instances on a single host. postmulti(1) implements two fundamental modes of operation. In iterator mode, it executes the same command for multiple Postfix instances. In life-cycle management mode, it adds or deletes one instance, or changes the multi-instance status of one instance. Each mode of operation has its own command syntax. For this reason, each mode is documented in separate sections below. BACKGROUND
A multi-instance configuration consists of one primary Postfix instance, and one or more secondary instances whose configuration directory pathnames are recorded in the primary instance's main.cf file. Postfix instances share program files and documentation, but have their own configuration, queue and data directories. Currently, only the default Postfix instance can be used as primary instance in a multi-instance configuration. The postmulti(1) command does not currently support a -c option to select an alternative primary instance, and exits with a fatal error if the MAIL_CONFIG environ- ment variable is set to a non-default configuration directory. See the MULTI_INSTANCE_README tutorial for a more detailed discussion of multi-instance management with postmulti(1). ITERATOR MODE
In iterator mode, postmulti performs the same operation on all Postfix instances in turn. If multi-instance support is not enabled, the requested command is performed just for the primary instance. Iterator mode implements the following command options: Instance selection -a Perform the operation on all instances. This is the default. -g group Perform the operation only for members of the named group. -i name Perform the operation only for the instance with the specified name. You can specify either the instance name or the absolute path- name of the instance's configuration directory. Specify "-" to select the primary Postfix instance. -R Reverse the iteration order. This may be appropriate when updating a multi-instance system, where "sink" instances are started before "source" instances. This option cannot be used with -p. List mode -l List Postfix instances with their instance name, instance group name, enable/disable status and configuration directory. Postfix-wrapper mode -p Invoke postfix(1) to execute the specified command. This option implements the postfix-wrapper(5) interface. o With "start"-like commands, "postfix check" is executed for instances that are not enabled. The full list of commands is specified with the postmulti_start_commands parameter. o With "stop"-like commands, the iteration order is reversed, and disabled instances are skipped. The full list of commands is specified with the postmulti_stop_commands parameter. o With "reload" and other commands that require a started instance, disabled instances are skipped. The full list of commands is specified with the postmulti_control_commands parameter. o With "status" and other commands that don't require a started instance, the command is executed for all instances. The -p option can also be used interactively to start/stop/etc. a named instance or instance group. For example, to start just the instances in the group "msa", invoke postmulti(1) as follows: # postmulti -g msa -p start Command mode -x Execute the specified command for all Postfix instances. The command runs with appropriate environment settings for MAIL_CONFIG, command_directory, daemon_directory, config_directory, queue_directory, data_directory, multi_instance_name, multi_instance_group and multi_instance_enable. Other options -v Enable verbose logging for debugging purposes. Multiple -v options make the software increasingly verbose. LIFE-CYCLE MANAGEMENT MODE With the -e option postmulti(1) can be used to add or delete a Postfix instance, and to manage the multi-instance status of an existing instance. The following options are implemented: Existing instance selection -a When creating or importing an instance, place the new instance at the front of the secondary instance list. -g group When creating or importing an instance, place the new instance before the first secondary instance that is a member of the specified group. -i name When creating or importing an instance, place the new instance before the matching secondary instance. With other life-cycle operations, apply the operation to the named existing instance. Specify "-" to select the primary Postfix instance. New or existing instance name assignment -I name Assign the specified instance name to an existing instance, newly-created instance, or imported instance. Instance names other than "-" (which makes the instance "nameless") must start with "postfix-". This restriction reduces the likelihood of name collisions with system files. -G group Assign the specified group name to an existing instance or to a newly created or imported instance. Instance creation/deletion/status change -e action "Edit" managed instances. The following actions are supported: init This command is required before postmulti(1) can be used to manage Postfix instances. The "postmulti -e init" command updates the primary instance's main.cf file by setting: multi_instance_wrapper = ${command_directory}/postmulti -p -- multi_instance_enable = yes You can set these by other means if you prefer. create Create a new Postfix instance and add it to the multi_instance_directories parameter of the primary instance. The "-I name" option is recommended to give the instance a short name that is used to construct default values for the private directories of the new instance. The "-G group" option may be specified to assign the instance to a group, otherwise, the new instance is not a member of any groups. The new instance main.cf is the stock main.cf with the parameters that specify the locations of shared files cloned from the primary instance. For "nameless" instances, you should manually adjust "syslog_name" to yield a unique "logtag" starting with "postfix-" that will uniquely identify the instance in the mail logs. It is simpler to assign the instance a short name with the "-I name" option. Optional "name=value" arguments specify the instance config_directory, queue_directory and data_directory. For example: # postmulti -I postfix-mumble -G mygroup -e create config_directory=/my/config/dir queue_directory=/my/queue/dir data_directory=/my/data/dir If any of these pathnames is not supplied, the program attempts to generate the pathname by taking the corresponding primary instance pathname, and by replacing the last pathname component by the value of the -I option. If the instance configuration directory already exists, and contains both a main.cf and master.cf file, create will "import" the instance as-is. For existing instances, create and import are identical. import Import an existing instance into the list of instances managed by the postmulti(1) multi-instance manager. This adds the instance to the multi_instance_directories list of the primary instance. If the "-I name" option is provided it specifies the new name for the instance and is used to define a default location for the instance configuration directory (as with cre- ate above). The "-G group" option may be used to assign the instance to a group. Add a "config_directory=/path" argument to override a default pathname based on "-I name". destroy Destroy a secondary Postfix instance. To be a candidate for destruction an instance must be disabled, stopped and its queue must not contain any messages. Attempts to destroy the primary Postfix instance trigger a fatal error, without destroying the instance. The instance is removed from the primary instance main.cf file's alternate_config_directories parameter and its data, queue and configuration directories are cleaned of files and directories created by the Postfix system. The main.cf and master.cf files are removed from the configuration directory even if they have been modified since initial creation. Finally, the instance is "deported" from the list of managed instances. If other files are present in instance private directories, the directories may not be fully removed, a warning is logged to alert the administrator. It is expected that an instance built using "fresh" directories via the create action will be fully removed by the destroy action (if first disabled). If the instance configuration and queue directories are populated with additional files (access and rewriting tables, chroot jail content, etc.) the instance directories will not be fully removed. The destroy action triggers potentially dangerous file removal operations. Make sure the instance's data, queue and configu- ration directories are set correctly and do not contain any valuable files. deport Deport a secondary instance from the list of managed instances. This deletes the instance configuration directory from the primary instance's multi_instance_directories list, but does not remove any files or directories. assign Assign a new instance name or a new group name to the selected instance. Use "-G -" to specify "no group" and "-I -" to specify "no name". If you choose to make an instance "nameless", set a suitable syslog_name in the corresponding main.cf file. enable Mark the selected instance as enabled. This just sets the multi_instance_enable parameter to "yes" in the instance's main.cf file. disable Mark the selected instance as disabled. This means that the instance will not be started etc. with "postfix start", "post- multi -p start" and so on. The instance can still be started etc. with "postfix -c config-directory start". Other options -v Enable verbose logging for debugging purposes. Multiple -v options make the software increasingly verbose. ENVIRONMENT
The postmulti(1) command exports the following environment variables before executing the requested command for a given instance: MAIL_VERBOSE This is set when the -v command-line option is present. MAIL_CONFIG The location of the configuration directory of the instance. CONFIGURATION PARAMETERS
config_directory (see 'postconf -d' output) The default location of the Postfix main.cf and master.cf configuration files. daemon_directory (see 'postconf -d' output) The directory with Postfix support programs and daemon programs. import_environment (see 'postconf -d' output) The list of environment parameters that a Postfix process will import from a non-Postfix parent process. multi_instance_directories (empty) An optional list of non-default Postfix configuration directories; these directories belong to additional Postfix instances that share the Postfix executable files and documentation with the default Postfix instance, and that are started, stopped, etc., together with the default Postfix instance. multi_instance_group (empty) The optional instance group name of this Postfix instance. multi_instance_name (empty) The optional instance name of this Postfix instance. multi_instance_enable (no) Allow this Postfix instance to be started, stopped, etc., by a multi-instance manager. postmulti_start_commands (start) The postfix(1) commands that the postmulti(1) instance manager treats as "start" commands. postmulti_stop_commands (see 'postconf -d' output) The postfix(1) commands that the postmulti(1) instance manager treats as "stop" commands. postmulti_control_commands (reload flush) The postfix(1) commands that the postmulti(1) instance manager treats as "control" commands, that operate on running instances. syslog_facility (mail) The syslog facility of Postfix logging. syslog_name (see 'postconf -d' output) The mail system name that is prepended to the process name in syslog records, so that "smtpd" becomes, for example, "postfix/smtpd". FILES
$daemon_directory/main.cf, stock configuration file $daemon_directory/master.cf, stock configuration file $daemon_directory/postmulti-script, life-cycle helper program SEE ALSO
postfix(1), Postfix control program postfix-wrapper(5), Postfix multi-instance API README FILES
Use "postconf readme_directory" or "postconf html_directory" to locate this information. MULTI_INSTANCE_README, Postfix multi-instance management HISTORY
The postmulti(1) command was introduced with Postfix version 2.6. LICENSE
The Secure Mailer license must be distributed with this software. AUTHOR(S) Victor Duchovni Morgan Stanley Wietse Venema IBM T.J. Watson Research P.O. Box 704 Yorktown Heights, NY 10598, USA POSTMULTI(1)
All times are GMT -4. The time now is 02:09 AM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy