Sponsored Content
Top Forums Shell Programming and Scripting Interpolation of two values in two different files Post 302962735 by jypark22 on Friday 18th of December 2015 04:32:35 PM
Old 12-18-2015
Thank you, Don.

I see your point. I will post my data clearly in the next post.

Best,

Jaeyoung

---------- Post updated 12-18-15 at 05:32 PM ---------- Previous update was 12-17-15 at 07:24 PM ----------

Thank you for all your help, Don and RudiC.

I have revised your elegant code a bit for my work.

Now, the updated code works successfully to calculate average values. I would appreciate your help.

I have a question about skipping non-data line. I tried Don's comment (/[{}]/), but it copied non-data lines on the top while remaining the original non-data lines. In addition, a few non-data string is changed to '0'. I marked in red in the following result.

Result.txt
Code:
 	cell (AND2X1_RVT) {
			timing () {
 				cell_rise ("del_1_7_7") {
 				}
 				rise_transition ("del_1_7_7") {
 				}
				cell_fall ("del_1_7_7") {
}
.... 
 	cell (AND2X1_RVT) {
			timing () {
 				related_pin : "0, ";
 				timing_sense : "0, ";
 				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("1.5,3,4.5,6,7.5,9,10.5, ", \
 					"12,13.5,15,16.5,18,19.5,21, ", \
 					"22.5,24,25.5,27,28,30,31.5, ", \
 					"33,34.5,36,37.5,39,40.5,42, ", \
 					"43.5,45,46.5,48,49.5,51,52.5, ", \
 					"54,55.5,57,58.5,60,61.5,63, ", \
 					"64.5,66,67.5,69,70.5,72,73.5, ");
 				}
 				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("75,76.5,78,79.5,81,82.5,84, ", \
 					"85.5,87,88.5,90,91.5,93,94.5, ", \
 					"96,97.5,99,100.5,102,103.5,105, ", \
 					"106.5,108,109.5,111,112.5,114,115.5, ", \
 					"117,118.5,120,121.5,123,124.5,126, ", \
 					"127.5,129,130.5,132,133.5,135,136.5, ", \
 					"138,139.5,141,142.5,144,145.5,147, ");
 				}
				cell_fall ("del_1_7_7") {
}

.....

AWKscript.s
Code:
awk -F"\"" '
/[{}]/          {print                     # copy non-data lines
                 next                      # and skip remaining steps
                }

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

#/^index_2("0.1, 0.25, 0.5, 1, 2, 4, 8"); /      {FOUND = 1
/^cell_rise ("del_1_7_7") { /      {FOUND = 1
                }

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 (M[i]+(N[i]-M[i])*0.5) ","
                 sub (/,$/, ", \"", $2)
                }
1
' OFS="" FileA.txt FileB.txt


FileA.txt
Code:
.... 
 	cell (AND2X1_RVT) {
			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("1, 2, 3, 4, 5, 6, 7", \
 					"8, 9, 10, 11, 12, 13, 14", \
 					"15, 16, 17, 18, 18, 20, 21", \
 					"22, 23, 24, 25, 26, 27, 28", \
 					"29, 30, 31, 32, 33, 34, 35", \
 					"36, 37, 38, 39, 40, 41, 42", \
 					"43, 44, 45, 46, 47, 48, 49");
 				}
 				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("50, 51, 52, 53, 54, 55, 56", \
 					"57, 58, 59, 60, 61, 62, 63", \
 					"64, 65, 66, 67, 68, 69, 70", \
 					"71, 72, 73, 74, 75, 76, 77", \
 					"78, 79, 80, 81, 82, 83, 84", \
 					"85, 86, 87, 88, 89, 90, 91", \
 					"92, 93, 94, 95, 96, 97, 98");
 				}
				cell_fall ("del_1_7_7") {
}

.....

FileB.txt
Code:
.... 
 	cell (AND2X1_RVT) {
			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("2, 4, 6, 8, 10, 12, 14", \
 					"16, 18, 20, 22, 24, 26, 28", \
 					"30, 32, 34, 36, 38, 40, 42", \
 					"44, 46, 48, 50, 52, 54, 56", \
 					"58, 60, 62, 64, 66, 68, 70", \
 					"72, 74, 76, 78, 80, 82, 84", \
 					"86, 88, 90, 92, 94, 96, 98");
 				}
 				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, 102, 104, 106, 108, 110, 112", \
 					"114, 116, 118, 120, 122, 124, 126", \
 					"128, 130, 132, 134, 136, 138, 140", \
 					"142, 144, 146, 148, 150, 152, 154", \
 					"156, 158, 160, 162, 164, 166, 168", \
 					"170, 172, 174, 176, 178, 180, 182", \
 					"184, 186, 188, 190, 192, 194, 196");
 				}
				cell_fall ("del_1_7_7") {
}

.....

I have tried many time by myself, but I could not find a way to skip non-data lines correctly. Any suggestions? Thank you in advance.

Best,

Jaeyoung



Best,

Jaeyoung
 

10 More Discussions You Might Find Interesting

1. 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

2. 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

3. 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

4. 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

5. 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

6. 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

7. 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

8. 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

9. 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

10. 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
All times are GMT -4. The time now is 12:03 PM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy