Sponsored Content
Top Forums Shell Programming and Scripting Awk: Multiple Replace In Column From Two Different Files Post 302839541 by siramitsharma on Friday 2nd of August 2013 01:27:53 AM
Old 08-02-2013
Awk: Multiple Replace In Column From Two Different Files

Master_1.txt
Code:
2372,MTS,AP
919821,Airtel,DL
0819,MTS,MUM
919849788001,Airtel,AP
1430,Aircel MP,20
405899143999999,MTS,KRL
USSDLIKE,MTS,DEL

Master_2.txt
Code:
919136,DL
9664,RAJ
919143,KOL
9888,PUN

Input File:
Code:
405899143999999,919821900030,919143227420,9664099976,919875089998,S,2
USSDLIKE,161A,91225,8104738198,405899136999995,S,5
2A65,919888799924,919136296645,9888997100,919875089998,S,1
MCA,,50009,8925682714,405899136999995,F,1

Requirement:
Column 1 & 2 to be matched from master_1.txt file & column 3 & 4 to be matched from master_2.txt file.

Output Required
Code:
MTS,KRL,Airtel,DL,KOL,RAJ,919875089998,S,2
MTS,DEL,161A,,91225,8104738198,405899136999995,S,5
2A65,,919888799924,,DL,PUN,919875089998,S,1
MCA,,,,50009,,8925682714,405899136999995,F,1

Code
Code:
awk -F, 'FNR==1 {++counter}
counter==1 {MASTERSPCGT[$1]=$2","$3;next}
counter==2 {MASTERMDNSERIES[$1]=$2;next}
{
 for (counter=1; counter<=2; counter++)
        {
          if ($counter in MASTERSPCGT) $counter=MASTERSPCGT[$counter]
                else if (substr($counter,1,9) in MASTERSPCGT) $counter=MASTERSPCGT[substr($counter,1,9)]
                else if (substr($counter,1,8) in MASTERSPCGT) $counter=MASTERSPCGT[substr($counter,1,8)]
                else if (substr($counter,1,7) in MASTERSPCGT) $counter=MASTERSPCGT[substr($counter,1,7)]
                else if (substr($counter,1,6) in MASTERSPCGT) $counter=MASTERSPCGT[substr($counter,1,6)]
                else if (substr($counter,1,5) in MASTERSPCGT) $counter=MASTERSPCGT[substr($counter,1,5)]
                else if (substr($counter,1,4) in MASTERSPCGT) $counter=MASTERSPCGT[substr($counter,1,4)]
                else $counter=$counter","
        }
        for (counter=3;counter<=4; counter++)
        {
         if (substr($counter,1,7) in MDNSERIES) $counter=MDNSERIES[substr($counter,1,7)]
                else if (substr($counter,1,4) in MDNSERIES) $counter=MDNSERIES[substr($counter,1,4)]
        }
}
1
' FS="," OFS="," master_1.txt master_2.txt inputfile

Required ouput is not coming for changes in column 3 & 4 but it is working fine for column 1 & 2. Can you please suggest changes
 

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

awk/sed column replace using column header - help

$ cat log.txt Name Age Sex Lcation nfld alias xsd CC 25 M XYZ asx KK Y BB 21 F XAS awe SS N SD 21 M AQW rty SD A How can I replace the column with header "Lcation" with the column with header "alias" and delete the "alias" column? so that the final output will become: Name Age Sex... (10 Replies)
Discussion started by: jkl_jkl
10 Replies

2. Shell Programming and Scripting

awk find and replace in multiple files

Hi I use the following code to replace ‘.' with ‘N' in my files and keep both versions. awk '{ gsub(/\./,"N"); print }' file_0001.txt > path/to/new/dir/file_0001.txt I need help on how to apply the code to 100 files instead of doing them one file at a time. The files are labeled... (7 Replies)
Discussion started by: jdhahbi
7 Replies

3. Shell Programming and Scripting

Join multiple files by column with awk

Hi all, I searched through the forum but i can't manage to find a solution. I need to join a set of files placed in a directory (~1600) by column, and obtain an output with first and second column common to each file, but following columns are taken from the file in the list (precisely the fourth... (10 Replies)
Discussion started by: macsx82
10 Replies

4. Shell Programming and Scripting

awk Print New Column For Every Two Lines and Match On Multiple Column Values to print another column

Hi, My input files is like this axis1 0 1 10 axis2 0 1 5 axis1 1 2 -4 axis2 2 3 -3 axis1 3 4 5 axis2 3 4 -1 axis1 4 5 -6 axis2 4 5 1 Now, these are my following tasks 1. Print a first column for every two rows that has the same value followed by a string. 2. Match on the... (3 Replies)
Discussion started by: jacobs.smith
3 Replies

5. Shell Programming and Scripting

Need to sum up a column value from multiple files into Credit and Debit categories using awk command

i have multiple files with Batch Header, Record detail & Batch trailer data in the files like : BH 20150225950050N8262 RD 20140918000000 99999999 unk Deferred Settlement -13950 BT01 -13950 *Above sample data donot have the spaces coorectly defined. I do have multiple batch trailer... (1 Reply)
Discussion started by: kcdg859
1 Replies

6. Shell Programming and Scripting

sed command to replace multiple column in one go

Hi, I want to replace the value in more than one column. For one column ,following command is working - sed 's/./$value_to_replace/$column number' file_name e.g. suppose this is input 1111000000 command - sed 's/./M/5' output= 1111M000000 For two column also command is like - cat... (22 Replies)
Discussion started by: Preeti Chandra
22 Replies

7. Shell Programming and Scripting

Do replace operation and awk to sum multiple columns if another column has duplicate values

Hi Experts, Please bear with me, i need help I am learning AWk and stuck up in one issue. First point : I want to sum up column value for column 7, 9, 11,13 and column15 if rows in column 5 are duplicates.No action to be taken for rows where value in column 5 is unique. Second point : For... (12 Replies)
Discussion started by: as7951
12 Replies

8. UNIX for Beginners Questions & Answers

How to copy a column of multiple files and paste into new excel file (next to column)?

I have data of an excel files as given below, file1 org1_1 1 1 2.5 100 org1_2 1 2 5.5 98 org1_3 1 3 7.2 88 file2 org2_1 1 1 2.5 100 org2_2 1 2 5.5 56 org2_3 1 3 7.2 70 I have multiple excel files as above shown. I have to copy column 1, column 4 and paste into a new excel file as... (26 Replies)
Discussion started by: dineshkumarsrk
26 Replies

9. UNIX for Beginners Questions & Answers

awk script to extract a column, replace one of the header and replace year(from ddmmyy to yyyy)

I have a csv which has lot of columns . I was looking for an awk script which would extract a column twice. for the first occurance the header and data needs to be intact but for the second occurance i want to replace the header name since it a duplicate and extract year value which is in ddmmyy... (10 Replies)
Discussion started by: Kunalcurious
10 Replies

10. UNIX for Beginners Questions & Answers

Extract a column and multiple by 1000 and replace it on same file

Hi All, I need to extract a position in the file and multiple the value by 1000 and the replace it . Original 0010001200084701217637306521200000000000010010000000 ---> 000847 * 1000 0010012700086001213437404323000000000000001001000000 ---> 000860 * 1000... (2 Replies)
Discussion started by: arunkumar_mca
2 Replies
PAPS(1) 						      General Commands Manual							   PAPS(1)

NAME
paps - UTF-8 to PostScript converter using Pango SYNOPSIS
paps [options] files... DESCRIPTION
paps reads a UTF-8 encoded file and generates a PostScript language rendering of the file. The rendering is done by creating outline curves through the pango ft2 backend. OPTIONS
These programs follow the usual GNU command line syntax, with long options starting with two dashes (`-'). A summary of options is included below. --landscape Landscape output. Default is portrait. --columns=cl Number of columns output. Default is 1. --font=desc Set the font description. Default is Monospace 12. --rtl Do rtl layout. --paper ps Choose paper size. Known paper sizes are legal, letter, a4. Default is A4. --bottom-margin=bm Set bottom margin in postscript points (1/72 inch). Default is 36. --top-margin=tm Set top margin. Default is 36. --left-margin=lm Set left margin. Default is 36. --right-margin=rm Set right margin. Default is 36. --help Show summary of options. --header Draw page header for each page. --markup Interpret the text as pango markup. --encoding=ENCODING Assume the documentation encoding is ENCODING. --lpi Set the lines per inch. This determines the line spacing. --cpi Set the characters per inch. This is an alternative method of specifying the font size. --stretch-chars Indicates that characters should be stretched in the y-direction to fill up their vertical space. This is similar to the texttops behaviour. AUTHOR
paps was written by Dov Grobgeld <dov.grobgeld@gmail.com>. This manual page was written by Lior Kaplan <kaplan@debian.org>, for the Debian project (but may be used by others). April 17, 2006 PAPS(1)
All times are GMT -4. The time now is 12:29 PM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy