Interpolation of two values in two different files


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Interpolation of two values in two different files
# 8  
Old 12-16-2015
With the samples in post#3 amended by your post#1 data, try
Code:
awk -F"(" '

FOUND           {while (/\\$/)  {getline X
                                 $0 = $0 X
                                }
                 FOUND = 0
                }

/^index_2/      {FOUND = 1
                }

                {gsub (/[ "\\;)]/, "", $2)
                }

FNR==NR         {if ($2) T[$1] = $2
                 next
                }

$1 in T         {n = split ($2, N, ",")
                 n = split (T[$1], M, ",")
                 $2 = "("
                 for (i=1; i<=n; i++) $2 = sprintf ("%s%f,", $2, (N[i]+M[i])/2)
                 sub (/,$/, ")", $2)
                }
1
' OFS="" file[12]
textA
index_2(0.100000,1.000000,2.000000,4.000000,8.000000,16.000000,32.000000)
values(0.047741,0.049992,0.054725,0.051878,0.054117,0.062570,0.060846,0.063073,0.065476)
textB(5.000000,1.000000,3.000000)
textC(3.000000)
textD

Correcting formatting issues is left as an exercise to the reader...
# 9  
Old 12-17-2015
Thank you, RudiC. I would appreciate your help.

Could you explain your code in detail? If you can, please line by line.

Best,

Jaeyoung

---------- Post updated at 05:35 PM ---------- Previous update was at 02:22 PM ----------

Hi RudiC,

Your code works great.

However, this does work if the number of array is greater than 1.

FileA.txt
Code:
.
.
index_2("0.1, 1, 2, 4, 8, 16, 32");
 values("0.0530208, 0.0345557, 0.0409915" \
 "0.0329737, 0.0344924, 0.0483888", \
 "0.0336141, 0.0351873, 0.0370214");
.
.
.
.
index_2("0.1, 1, 2, 4, 8, 16, 32");
 values("0.0330208, 0.0545557, 0.0409915" \
 "0.0329737, 0.0344924, 0.0483888", \
 "0.0336141, 0.0351873, 0.0370214");
.
.

FileB.txt
Code:
.
.
index_2("0.1, 1, 2, 4, 8, 16, 32");
 values("0.0624608, 0.0654286, 0.0684585", \
 "0.0707829, 0.0737413, 0.0767505", \
 "0.0880787, 0.0909583, 0.0939307");
.
.
.
.
index_2("0.1, 1, 2, 4, 8, 16, 32");
 values("0.0624608, 0.0654286, 0.0684585", \
 "0.0707829, 0.0737413, 0.0767505", \
 "0.0880787, 0.0909583, 0.0939307");
.
.

Result.txt
Code:
.
.
index_2(0.100000,1.000000,2.000000,4.000000,8.000000,16.000000,32.000000,0.000000)
 values(0.047741,0.059992,0.054725,0.052638,0.061065,0.055182,0.061633,0.063990,0.046965)
.
.
.
.
index_2(0.100000,1.000000,2.000000,4.000000,8.000000,16.000000,32.000000,0.000000)
 values(0.047741,0.059992,0.054725,0.052638,0.061065,0.055182,0.061633,0.063990,0.046965)
.
.

The result of the second array was not updated. Could you let me know how to revise your code to work correctly if the number of array is greater than 1?

Best,

Jaeyoung
# 10  
Old 12-17-2015
Code:
awk -F"(" '                                     # make "(" the field separator

FOUND           {while (/\\$/)  {getline X      # if last line had "index_2", read and append
                                 $0 = $0 X      # all lines with a continuation char "\" to $0
                                }
                 FOUND = 0                      # done with the values
                }

/^index_2/      {FOUND = 1                      # keep info that index_2 was found for above
                }

                {gsub (/[ "\\;)]/, "", $2)      # remove all occurrences of unwanted chars
                }

FNR==NR         {if ($2) T[$1] = $2             # for 1. file: store values (if present) in T arr
                 next                           # don't continue processing THIS line
                }

$1 in T         {n = split ($2, N, ",")         # split all values into N arr
                 n = split (T[$1], M, ",")      # split all 1. file values into M arr
                 $2 = "("                       # start new $2
                 for (i=1; i<=n; i++) $2 = $2 (N[i]+M[i])/2 ","         # add average values
                 sub (/,$/, ")", $2)            # to $2; remove last comma
                }
1                                               # print the actual line (with new values)
' OFS="" file[12]

---------- Post updated at 23:00 ---------- Previous update was at 22:50 ----------

Quote:
Originally Posted by jypark22
.
.
.
Could you let me know how to revise your code to work correctly if the number of array is greater than 1?
.
.
.
A bit surprising, ain't it?

If the texts are IDENTICAL line by line except for the numerical values, try
Code:
awk -F"(" '

FOUND           {while (/\\$/)  {getline X
                                 $0 = $0 X
                                }
                 FOUND = 0
                }

/^index_2/      {FOUND = 1
                }

                {gsub (/[ "\\;)]/, "", $2)
                }

FNR==NR         {if ($2) T[FNR] = $2
                 next
                }

FNR in T         {n = split ($2, N, ",")
                 n = split (T[FNR], M, ",")
                 $2 = "("
                 for (i=1; i<=n; i++) $2 = $2 (N[i]+M[i])/2 ","
                 sub (/,$/, ")", $2)
                }
1
' OFS="" file[12]
textA
index_2(0.1,1,2,4,8,16,32)
values(0.0577408,0.0499921,0.054725,0.0526376,0.061065,0.0551823,0.061633,0.0639899)
textB(5,1,3)
index_2(0.1,1,2,4,8,16,32)
values(0.0477408,0.0599922,0.054725,0.0526376,0.061065,0.0551823,0.061633,0.0639899)
textC(3)
textD

This User Gave Thanks to RudiC For This Post:
# 11  
Old 12-17-2015
Thank you so much!!!. That problem is resolved.

However, I encountered a strange problem with the new code. 0 is inserted after "(".

I only posted a part of my data at the first time. My data goes as shown below. 100 are values that I want to change.



Code:
			.... 
			timing () {
 				related_pin : "A1";
 				timing_sense : "positive_unate";
 				cell_rise ("del_1_7_7") {
 					index_1("0.016, 0.032, 0.064, 0.128, 0.256, 0.512, 1.024");
 					index_2("0.1, 0.25, 0.5, 1, 2, 4, 8");
 					values("100, 100, 100, 100, 100, 100, 100", \
 					"100, 100, 100, 100, 100, 100, 100", \
 					"100, 100, 100, 100, 100, 100, 100", \
 					"100, 100, 100, 100, 100, 100, 100", \
 					"100, 100, 100, 100, 100, 100, 100", \
 					"100, 100, 100, 100, 100, 100, 100", \
 					"100, 100, 100, 100, 100, 100, 100");
 				}
 				rise_transition ("del_1_7_7") {
 					index_1("0.016, 0.032, 0.064, 0.128, 0.256, 0.512, 1.024");
 					index_2("0.1, 0.25, 0.5, 1, 2, 4, 8");
					values("100, 100, 100, 100, 100, 100, 100", \
 					"100, 100, 100, 100, 100, 100, 100", \
 					"100, 100, 100, 100, 100, 100, 100", \
 					"100, 100, 100, 100, 100, 100, 100", \
 					"100, 100, 100, 100, 100, 100, 100", \
 					"100, 100, 100, 100, 100, 100, 100", \
 					"100, 100, 100, 100, 100, 100, 100");
 				}
				cell_fall ("del_1_7_7") {

.....


Results are shown below. I observed the values that I wanted to modify did not change, only "0" is inserted after "("
Code:
.... 
 			timing (0)
 				related_pin : "A1";
 				timing_sense : "positive_unate";
 				cell_rise (0)
 					index_1(0.016,0.032,0.064,0.128,0.256,0.512,1.024)
 					index_2(0.1,0.25,0.5,1,2,4,8)
 					values(100,100,100,100,100,100,100,0)
 					"100, 100, 100, 100, 100, 100, 100", \
 					"100, 100, 100, 100, 100, 100, 100", \
 					"100, 100, 100, 100, 100, 100, 100", \
 					"100, 100, 100, 100, 100, 100, 100", \
 					"100, 100, 100, 100, 100, 100, 100", \
 					"100, 100, 100, 100, 100, 100, 100");
 				}
 				rise_transition (0)
 					index_1(0.016,0.032,0.064,0.128,0.256,0.512,1.024)
 					index_2(0.1,0.25,0.5,1,2,4,8)
 					values(100,100,100,100,100,100,100,0)
 					"100, 100, 100, 100, 100, 100, 100", \
 					"100, 100, 100, 100, 100, 100, 100", \
 					"100, 100, 100, 100, 100, 100, 100", \
 					"100, 100, 100, 100, 100, 100, 100", \
 					"100, 100, 100, 100, 100, 100, 100", \
 					"100, 100, 100, 100, 100, 100, 100");
 				}
 				cell_fall (0)
....

Any help is appreciated. I can share my data file with you if it would be helpful to provide comments.

Best,

Jaeyoung
# 12  
Old 12-17-2015
That value is 0 as there's text string inside the parentheses. Wouldn't it have been nice if the real data had been known from the beginning?
This User Gave Thanks to RudiC For This Post:
# 13  
Old 12-17-2015
Yes, I am sorry about that. I couldn't share my data files because of confidential issue. Data files are from a company for educational purpose, but I think that is not appropriate to post data in the forum.

I want to share it to you, but there is no way to send a private message currently. Could you send me a private message containing you email address if you are okay? I will share data files.


Best,

Jaeyoung
# 14  
Old 12-17-2015
Quote:
Originally Posted by jypark22
Yes, I am sorry about that. I couldn't share my data files because of confidential issue. Data files are from a company for educational purpose, but I think that is not appropriate to post data in the forum.

I want to share it to you, but there is no way to send a private message currently. Could you send me a private message containing you email address if you are okay? I will share data files.


Best,

Jaeyoung
We don't need or want you to post sensitive data. But, for us to help you write code to process data, we absolutely require a clear description and/or a representative sample (with sensitive data scrubbed) that describes what needs to be processed and what needs to be ignored.

With your latest sample it appears that your problem lines could be handled by changing:
Code:
FOUND           {while (/\\$/)  {getline X      # if last line had "index_2", read and append

to something like:
Code:
/[{}]/          {print                          # copy non-data lines
                 next                           # and skip remaining steps
                }

FOUND           {while (/\\$/)  {getline X      # if last line had "index_2", read and append


Last edited by Don Cragun; 12-17-2015 at 07:31 PM.. Reason: Fix typo: s/problems lines/problem lines/
This User Gave Thanks to Don Cragun For This Post:
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. UNIX for Beginners Questions & Answers

Replace Stub Values In One Group Of Files With Actual Values From Another Group Of Files

I have two directories of files (new-config-files and old-config-files): new-config-files/this-db/config.inc.php new-config-files/that-db/config.inc.php new-config-files/old-db/config.inc.php new-config-files/new-db/config.inc.php new-config-files/random-database/config.inc.php etc. ... (4 Replies)
Discussion started by: spacegoose
4 Replies

2. Shell Programming and Scripting

An interpolation between two files

Dear all, I always appreciate your help. I am an electrical engineer. I am using a tool for timing analysis of a circuit. I would like to interpolate results from two timing reports at different voltages (0.945V and 0.78V). If voltage is decreased, data arrival time is increased. For... (4 Replies)
Discussion started by: jypark22
4 Replies

3. UNIX for Dummies Questions & Answers

Interpolation if there is no exact match for value

Dear all, could you help me with following question. There are two datasets (below). I need to find match between BP values from data1 and data2, and add corresponding CM value from data2 into data1. if there is not exact match, the corresponding CM value should be calculated using interpolation.... (20 Replies)
Discussion started by: kush
20 Replies

4. Shell Programming and Scripting

Expand & Interpolation

Dear All, I have input like this, infile: 10 464310.16 20 464309.44 30 464309.02 40 464316.93 ... ... Desired output per step: out_step01: 10 464310.16 11 12 13 14 (9 Replies)
Discussion started by: attila
9 Replies

5. Shell Programming and Scripting

Query the table and return values to shell script and search result values from another files.

Hi, I need a shell script, which would search the result values from another files. 1)execute " select column1 from table_name" query on the table. 2)Based on the result, need to be grep from .wft files. could please explain about this.Below is the way i am using. #!/bin/sh... (4 Replies)
Discussion started by: Rami Reddy
4 Replies

6. Shell Programming and Scripting

Hi ! whether it is possible to do interpolation in scripting...

Hi ! Experts... I just wanted to know whether it is possible in scripting...to do interpolation.... if so....have a look on my data file I need temperature and salinity value with a bin size of 0.5 m output looks somewhat like this dep temp sal 0.5 25 0.077 1 25 ... (12 Replies)
Discussion started by: nex_asp
12 Replies

7. Shell Programming and Scripting

Compare values in two files. For matching rows print corresponding values from File 1 in File2.

- I have two files (File 1 and File 2) and the contents of the files are mentioned below. - I am trying to compare the values of Column1 of File1 with Column1 of File2. If a match is found, print the corresponding value from Column2 of File1 in Column5 of File2. - I tried to modify and use... (10 Replies)
Discussion started by: Santoshbn
10 Replies

8. Shell Programming and Scripting

Interpolation using awk

Hi all, Consider I have a text file containing: 1003 60 1005 80 1100 110 Based on that file I need to create another file which is containing value from 1001 till 1100 which is a linear interpolation between two point (for 1004; 1006;1007 until 1109) and extrapolation based on 2... (7 Replies)
Discussion started by: ardy_yana
7 Replies

9. Shell Programming and Scripting

Cat Values from Several files if it meets criteria for column values

I have results from some statistical analyses. The format of the results are as given below: I want to select lines that have a p-value (last column) less than 0.05 from all the results files (*.results) and cat to a new results file. It would be very nice if a new column is added that tells... (2 Replies)
Discussion started by: genehunter
2 Replies

10. UNIX for Dummies Questions & Answers

variable interpolation

I've become obsessed with trying to get this to work. As of yet, I am unable to figure it out. Unfortunately, I don't have Linux or UNIX available when I get home. Anyone have tips for me on how I can pass param1 to ID via use of COUNTER and loop? thx. LIMIT=6 param1="999999999" export... (0 Replies)
Discussion started by: egkumpe
0 Replies
Login or Register to Ask a Question