Replace content of one column to another if match found
Hi All,
I have two files one having some transaction IDs only and sample content as follows: Code:
SDP-DM-100755485 Code:
SDP-DM-100689014,2010-12-21 19:24:29 GMT+05:30,CRBT,18,UK,Default,B_11170244,9058629605,405818120653083,,Pre-Paid,Comviva,default_provider,009114500001366,,0.0,code0,0,,Caller Tune,,UK#11561723,,1292939663242,VAS0003ALL,52211,,,UK,,0.0,Grace, Please guide me for the above. Thanks in advance |
Hi,
Try the Perl script between the ======================================= lines, supposing you called it script.pl and made it executable. Launch the line below from shell prompt script.pl first_file second_file > wanted_file ======================================= #!/usr/bin/perl use strict; my ($IDs, $fields, @IDs, @fields); $IDs = shift; open (IDs, $IDs); @IDs = <IDs>; chomp @IDs; $IDs = join(',', '', @IDs, ''); $fields = shift; open (FIELDS, $fields); while (<FIELDS>) { chomp; @fields = split /,/; if ($IDs =~ /,$fields[0],/) { $fields[17] = $fields[15]; } print join(',', @fields), "\n"; } ======================================= Regards, Tshimanga. |
So as you are some 30+ questions in and you have been helped several times, what have you come up with so far?
Let us know where you are getting stuck? |
An awk solution:
Code:
BEGIN { |
Hi Colucix,
Please guide me where i can mention the two filenames used in the following code provided by you: Code:
BEGIN { |
I assumed the file containing the transaction IDs (that is the patterns to look for) is "transaction_ids". If you put the suggested code in a file, e.g. "test.awk" you can run it passing the file with transaction details as argument:
Code:
awk -f test.awk transaction_details_file Code:
#!/bin/awk -f Code:
./test.awk transaction_details_file Code:
awk ' |
All times are GMT -5. The time now is 04:27 PM. |