Sponsored Content
Top Forums Shell Programming and Scripting Search & replace content using awk/gsub Post 302780109 by siramitsharma on Thursday 14th of March 2013 12:35:01 AM
Old 03-14-2013
Search & replace content using awk/gsub

Hi,
I have two files master.txt & reference.txt. Sample below

Master.txt
Code:
2372,MTS,AP
919848001104,Airtel,DL
0819,MTS,MUM
919849788001,Airtel,AP
1430,Aircel MP,20

Reference.txt
Code:
2372,919848701430,46467
919848002372,2372,47195
2372,919849788001,59027
0819,028803,1
0819,029801,1
0819,2372,1

Output which is coming is as follows:
Code:
MTS AP,91984870Aircel MP,46467
91984800MTS AP,MTS AP,47195
MTS AP,Airtel,AP59027
MTS MUM,028803,1
MTS MUM,029803,1
MTS MUM,MTS AP,1

Requirement:
Only the exact match of each separator field should be replaced in reference text,i.e, output should look like as follows

MTS AP,919848701430,46467
919848002372,MTS AP,47195
MTS AP,Airtel,AP59027
MTS MUM,028803,1
MTS MUM,029803,1
MTS MUM,MTS AP,1

Code is
awk -F, '
NR==FNR {rep[$1]=$2" "$3; next}
{ for (r in rep) gsub(r,rep[r],$0); print $0}' Master.txt Reference.txt

Please help in getting the code changed as per the required output for the exact match length

Last edited by Franklin52; 03-14-2013 at 04:20 AM.. Reason: Please use code tags for data and code samples
 

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

How do I search first&second string & copy all content between them to other file?

Hi All, How do I search first string & second string and copy all content between them from one file to another file? Please help me.. Thanks In Advance. Regards, Pankaj (12 Replies)
Discussion started by: pankajp
12 Replies

2. Shell Programming and Scripting

awk and gsub - how to replace only the first X occurrences

I have a text (text.txt) and I would like to replace only the first 2 occurrences of a word (but I might need to replace more): For example, if text is this: CAR sweet head hat red yellow CAR book brown tiger CAR cow CAR CAR milk I would like to replace the word "CAR" with word... (12 Replies)
Discussion started by: bingel
12 Replies

3. Shell Programming and Scripting

Search & Replace regex Perl one liner to AWK one liner

Thanks for giving your time and effort to answer questions and helping newbies like me understand awk. I have a huge file, millions of lines, so perl takes quite a bit of time, I'd like to convert these perl one liners to awk. Basically I'd like all lines with ISA sandwiched between... (9 Replies)
Discussion started by: verge
9 Replies

4. Shell Programming and Scripting

Using of gsub function in AWK to replace space by underscore

I must design a UNIX script to monitor files whose size is over a threshold of 5 MB in a specific UNIX directory I meet a problem during the for loop in my script. Some file names contain spaces. ls -lrt | awk '$5>=5000000 && length($8)==5 {gsub(/ /,"_",$9); print};' -rw-r--r-- 1 was61 ... (2 Replies)
Discussion started by: Scofield38
2 Replies

5. Shell Programming and Scripting

awk/sed to search & replace data in first column

Hi All, I need help in manipulating the data in first column in a file. The sample data looks like below, Mon Jul 18 00:32:52 EDT 2011,NULL,UAT Jul 19 2011,NULL,UAT 1] All field in the file are separated by "," 2] File is having weekly data extracted from database 3] For eg.... (8 Replies)
Discussion started by: gr8_usk
8 Replies

6. Shell Programming and Scripting

awk + gsub to search multiple input values & replace with located string + extra text

Hi all. I have the following command that is successfully searching for any one of the strings on all lines of a file and replacing it with the instructed value. cat inputFile | awk '{gsub(/aaa|bbb|ccc|ddd/,"1234")}1' > outputFile This does in fact replace any occurrence of aaa, bbb,... (2 Replies)
Discussion started by: dazhoop
2 Replies

7. Shell Programming and Scripting

awk search/replace specific field, using variables for regexp & subsitution then overwrite file

Hello, I'm trying the solve the following problem. I have a file which I intend to use as a csv called master.csv The columns are separated by commas. I want to change the text on a specific row in either column 3,4,5 or 6 from xxx to yyy depending upon if column 1 matches a specified pattern.... (3 Replies)
Discussion started by: cyphex
3 Replies

8. Shell Programming and Scripting

Search & Replace content of files using gsub in awk

Hi,I have 2 files master.txt & reference.txt as shown below & i require o/p as mentioned in file 3 using awk but content is not replacing properlymaster.txt:... (15 Replies)
Discussion started by: siramitsharma
15 Replies

9. Shell Programming and Scripting

Replace characters in string with awk gsub

Hi I have a source file that looks like a,b,c,d,e,f,g,h,t,DISTI(USD),MSRP(USD),DIST(EUR),MSRP(EUR),EMEA-DISTI(USD),EMEA-MSRP(USD),GLOBAl-DISTI(USD),GLOBAL-MSRP(USD),DISTI(GBP), MSRP(GBP) I want to basically change MSRP(USD) to MSRP,USD and DIST(EUR) to DIST,EUR and likewise for all i'm using... (3 Replies)
Discussion started by: r_t_1601
3 Replies

10. Shell Programming and Scripting

awk gsub command to replace multiple spaces

Hi Forum. I'm trying to cleanup the following data elements (To remove any occurences of commas and any extra spaces) while preserving the <TAB> delimiter using awk gsub but I have not been successful. Original Data: 4365 monte des source rue,, ,<TAB>trevost<TAB>QC Desired Data:... (1 Reply)
Discussion started by: pchang
1 Replies
mailconfig(8)						      System Manager's Manual						     mailconfig(8)

NAME
mailconfig - Sets up the routing and delivery of mail for the system. SYNOPSIS
/usr/sbin/mailconfig [-ui cui [cuioptions] | gui [x resources]] OPTIONS
Specifies the user interface to be invoked The mailconfig program can be run using either the graphical user interface (gui) or the command-line interface (cui): Specifies the graphical user interface. Sample command line: mailconfig -ui gui [x resources]: The mailconfig -ui gui command accepts all of the standard X Toolkit command-line options, which are documented in the OPTIONS section of the X(1X) reference page. Specifies the command-line interface. Sample command line: mailconfig -ui cui [cuioptions]: The mailconfig -ui cui command accepts the following command-line options: Provides a brief help message, listing all configurable mailconfig components and the actions that can be performed on them. Sample command line: mailconfig -ui cui -Help Provides a detailed help message on how to configure the specified component. Sample command line: mailconfig -ui cui -host Help In the help message, the actions and attribute values that are pertinent to the specified component are listed. The following is a list of all possible actions for all configurable components: Creates a new configuration for the specified com- ponent. Modifies the specified component's existing configuration. Adds a new attribute value to the specified component's exist- ing configuration. Removes the specified component's existing configuration. Deletes an attribute value from the specified compo- nent's existing configuration. Lists all attribute values in the specified component. Lists (on stdout) all attributes that the specified component can use. A subset of these attributes is listed on the create action line of the help provided when you issue the mailconfig -ui cui -<component> Help command. Lists any attributes used to define the uniqueness of the specified component. Performs a specific action (for example, modify) on the specified component, optionally altering one or more of the component's attributes. Sample command line: mailconfig -ui cui -host modify alias=frew DESCRIPTION
The Mail Configuration application, mailconfig, is used by the system administrator to set up the routing and delivery of mail for the sys- tem. The protocols that can be used are: DECnet, DECnet/OSI, MTS, UUCP, Internet, X.25, POP, and IMAP. The configuration of POP and IMAP services under mailconfig is transparent to the system administrator. Dependencies: Before using Mail Configuration, be sure to configure the system using the following applications, which you can access from the SysMan Configuration Checklist: Network Configuration BIND Configuration NFS Configuration UUCP or other network protocols that you use to send mail NTP NIS The mailconfig application can be invoked from: The CDE Application Manager Application Group: System_Admin Desktop_Apps Subgroup: Configuration Configuration Subgroup: Mail To start mailconfig from the command line, enter /usr/sbin/mailconfig. Online help is available for the mailconfig application. To get help, click on any Help button or use the Help pull-down menu. NOTES
The -focus option is not valid because mail is configured throughout a TruCluster Server cluster; hence, all nodes in the cluster have the same mail configuration. For a cluster to handle any mail protocol, other than the Internet protocol, all nodes must have that protocol installed, configured, and operating in the same fashion. RESTRICTIONS
You must have the appropriate privileges to use this application. EXAMPLES
Opens Mail Configuration in the graphical user interface. mailconfig -ui gui Opens Mail Configuration in the command-line interface. mailconfig -ui cui Provides a brief help message for the command-line interface of Mail Configuration, listing all configurable mailconfig components and the actions that can be performed on them. mailconfig -ui cui -Help Provides a detailed help message on how to configure host, the specified component. mailconfig -ui cui -host Help Opens Mail Configuration in the command-line interface while changing the host alias to frew. mailconfig -ui cui -host modify alias=frew The /usr/dt/appconfig/help/C/MailConfig.sdl command opens the Mail Configu- ration help volume from the command line without running the application. /usr/dt/bin/dthelpview -h FILES
Mail Configuration help volume Specify the environment variables that define part of the mail configuration on the system Current sendmail configuration settings Previous sendmail configuration settings Original sendmail configuration settings Current mail configuration in stanza file format SEE ALSO
Commands: mailsetup(8), rc.config(8) Files: aliases(4), sendmail.cf(4), stanza(4) Network: mail_intro(7), mail_manual_setup(7) mailconfig(8)
All times are GMT -4. The time now is 01:59 AM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy