Replacing match lines from one file with another file


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Replacing match lines from one file with another file
# 8  
Old 01-18-2018
Lets say with the example I have file1:

This is file1 contents:

Code:
include "~$XFR/conv.xfr";

/*C1_T0*/
out :: conv_c1_t0(in) =
begin
out.field1 ::decimal_lpad(in..efgh);
out.country2 :: in.country.sub_country;
out.cur :: if(!is_defined(in.tran.ghjk) || is_blank(string_lrtrim(in.tran.ghjk)))
                 string_lpad(" ",6)
                else
                string_repad(in.tran.ghjk,6);
end;

/*C1_T1*/

out :: conv_c1_t1(in) =
begin

out.test ::decimal_lpad(in..test1);
out.zipcode :: in.state.state1;
out.pin :: in.country.state;
out.adr :: in.adr1.adr2;

end;

And file2 contents be like with extra one filed in conv_c1_t1:

Code:
out :: conv_c1_t1(in) =
begin

out.test ::decimal_lpad(in..test1);
out.zipcode :: in.state.state1;
out.pin :: in.country.state;
out.adr :: in.adr1.adr2;
out.date :: if(!is_defined(in.temp.date1) || is_blank(string_lrtrim(in.temp.date1)))
                 string_lpad(" ",6)
                else
                string_repad(in.temp.date1,6);
end;


Now My output should be like out :: conv_c1_t0(in) = from file1 and updated function of out :: conv_c1_t1(in) = from file 2 as it contains one extra field :

Code:
include "~$XFR/conv.xfr";

/*C1_T0*/
out :: conv_c1_t0(in) =
begin
out.field1 ::decimal_lpad(in..efgh);
out.country2 :: in.country.sub_country;
out.cur :: if(!is_defined(in.tran.ghjk) || is_blank(string_lrtrim(in.tran.ghjk)))
                 string_lpad(" ",6)
                else
                string_repad(in.tran.ghjk,6);
end;

/*C1_T1*/

out :: conv_c1_t1(in) =
begin

out.test ::decimal_lpad(in..test1);
out.zipcode :: in.state.state1;
out.pin :: in.country.state;
out.adr :: in.adr1.adr2;
out.date :: if(!is_defined(in.temp.date1) || is_blank(string_lrtrim(in.temp.date1)))
                 string_lpad(" ",6)
                else
                string_repad(in.temp.date1,6);
end;

Note : File 2 we are generating in our script dynamically.


Moderator's Comments:
Mod Comment Please use CODE tags as required by forum rules!

Last edited by RudiC; 01-18-2018 at 07:32 AM.. Reason: Added CODE tags.
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. UNIX for Beginners Questions & Answers

Match pattern only between certain lines in entire file

Hello, I have input that looks like this: * 0 -1 103 0 0 m. 7 LineNr 23 ClauseNr 1: 1: 1: 304: 0 0 SentenceNr 13 TxtType: Q Pargr: 2.1 ClType:MSyn PS004,006 ZBX= 0 1 1 0 7 -1 -1 3 2 3 2 -1 1 1 -1 -1 -1 -1 0 501 0 PS004,006 ZBX ... (2 Replies)
Discussion started by: jvoot
2 Replies

2. Shell Programming and Scripting

Matching and Replacing file lines starting with $

Here is the task that I was presented with: I am dealing with about a 10,000 line input deck file for an analysis. About 10 separate blocks of around 25 lines of code each need to be updated in the input deck. The input deck (deckToChange in the code below) comes with 2 separate files. File 1... (5 Replies)
Discussion started by: tiktak292
5 Replies

3. Shell Programming and Scripting

Help with ksh-to read ip file & append lines to another file based on pattern match

Hi, I need help with this- input.txt : L B white X Y white A B brown M Y black Read this input file and if 3rd column is "white", then add specific lines to another file insert.txt. If 3rd column is brown, add different set of lines to insert.txt, and so on. For example, the given... (6 Replies)
Discussion started by: prashob123
6 Replies

4. Shell Programming and Scripting

Replacing a single line with multiple lines in a file

Hi Am confused with the usage of "sed" command I want to replace a single line with multiple lines of a file.. eg., A file has Hi, How are you? I need to replace as Am fine What are You doing? I used the script as string1="Hi, How are you?" echo "$string1 is the value"... (4 Replies)
Discussion started by: Priya Amaresh
4 Replies

5. Shell Programming and Scripting

Replacing lines which match certain criteria

Hi, I have code which is like this <TABLE name="UsageDetail_24> <ROW> <Date24><!]></Date24> <Time24><!]></Time24> <Destination24><!]></Destination24> <Rate24><!]></Rate24> <Duration24><!]></Duration24> <Cost24><!]></Cost24> <Allowance24><!]></Allowance24> </ROW> <ROW>... (3 Replies)
Discussion started by: legolad
3 Replies

6. Shell Programming and Scripting

Replacing multiple lines in file from another file

Hi All, I'm trying to parse a XML file and replace few lines of file with text present in another file. But only issue is I need to replace only those lines from XML which are preceeding the JOBNAME =*RRN* For ex test.xml(content of XML file in which I want to replace lines is ) <JOB . . .... (10 Replies)
Discussion started by: techneel
10 Replies

7. Shell Programming and Scripting

Strings from one file which exactly match to the 1st column of other file and then print lines.

Hi, I have two files. 1st file has 1 column (huge file containing ~19200000 lines) and 2nd file has 2 columns (small file containing ~6000 lines). ################################# huge_file.txt a a ab b ################################## small_file.txt a 1.5 b 2.5 ab ... (4 Replies)
Discussion started by: AshwaniSharma09
4 Replies

8. Shell Programming and Scripting

Replacing Block of lines in a text file

Dear All, Regards of the Day. I have a text file with some functions: Function1 { parameter 1 parameter 2 parameter 3 } end Function2 { parameter 1 parameter 2 parameter 3 } (1 Reply)
Discussion started by: ashisharora
1 Replies

9. Shell Programming and Scripting

replacing specific lines in a file

Hi there I have a file which has the lines # Serial number for hostid EXP_SERIAL_="" These lines could be anywhere in the file as far as line numbers go, I would like replace these two lines with # Serial number for hostid $var1 EXP_SERIAL_$var1="$var2" Is there a quick and simple... (6 Replies)
Discussion started by: hcclnoodles
6 Replies

10. UNIX for Advanced & Expert Users

replacing first line or lines in a file

hey guys, how do i replace only a line within a file without messing up the rest of the contents of the file? see, if possible can you guys give me a straight forward way to do this. i dont want a complex command. what i mean is i know i can accomplish this by using sed, well, i think i can,... (3 Replies)
Discussion started by: Terrible
3 Replies
Login or Register to Ask a Question