Sponsored Content
Top Forums Shell Programming and Scripting Read values from second file in awk Post 302901885 by EAGL€ on Friday 16th of May 2014 08:14:12 AM
Old 05-16-2014
Quote:
Originally Posted by RudiC
I'm not sure either I understood your request correctly, nor am I convinced your awk will run fine. But, to output the relevant state's name, add this to your awk script and put file2 as first argument:
Code:
awk -v stat=$2 'NR==FNR && $1==stat {STATE=$2} ... END {print "... for " STATE "state =", ...} ' file2 $j

Thanks a lot Rudic, that was what exactly i wanted,

Now i can use a second file to read properties from.

If it is suitable me asking another thing about the printing results, i would like to find out how i can mark spesific results with a star "*" at the end, where average processing time is larger than 300;

this is the code part:

Code:
echo "$j" && nawk -v stat=$2 'NR==FNR && $1==stat{STATE=$2}/State=\[stat\]Action.*in/gsub(/^\[|\]/,"",$(NF-1)){sum+=$(NF-1);avg=(sum/NR)} END { print "Avg Proc Time for " STATE " =",avg}' state.cfg $j >> avg_proc_time_results.txt;

7

the output is now like the following:

Code:
-bash-3.00$ cat avg_proc_time_results.txt 
Avg Proc Time for Charging = 199.98
Avg Proc Time for Charging = 200.021
Avg Proc Time for Charging = 214.448
Avg Proc Time for Charging = 213.565
Avg Proc Time for Charging = 170.646
Avg Proc Time for Charging = 168.457
Avg Proc Time for Charging = 265.9
Avg Proc Time for Charging = 258.402

desired output:
Code:
-bash-3.00$ cat avg_proc_time_results.txt 
Avg Proc Time for Charging = 199.98
Avg Proc Time for Charging = 200.021
Avg Proc Time for Charging = 214.448
Avg Proc Time for Charging = 213.565
Avg Proc Time for Charging = 170.646
Avg Proc Time for Charging = 168.457
Avg Proc Time for Charging = 265.9*
Avg Proc Time for Charging = 258.402*

KR
Eagle

Last edited by EAGL€; 05-20-2014 at 04:47 AM..
 

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

awk/sed script to read values from parameter files

Hi, I am writing a shell program that executes a lot of Oracle SQL Files on different databases based on the enviroment setting value. I am trying to design a parameter file where i can store the environment values for all the databases in the below format Environment File File Name... (6 Replies)
Discussion started by: rajan_san
6 Replies

2. Shell Programming and Scripting

Read values from a file

Hi , I have a file with the following content I need the read the year and reporting from this file and store them in variables. I understand that we can read the file delimited by'=' but not sure how to extract the values correctly. Thanks in advance Regards (3 Replies)
Discussion started by: w020637
3 Replies

3. Shell Programming and Scripting

AWK: read values from file1; search for values in file2

I have read another post about this issue and am wondering how to adapt it to my own, much simpler, issue. I have a file of user IDs like so: 333333 321321 546465 ...etc I need to take each number and use it to print records wherein the 5th field matches the user ID pulled from the... (2 Replies)
Discussion started by: Bubnoff
2 Replies

4. Shell Programming and Scripting

Read variables and their values from file

Hi, I want to read the variables and the values from the txt file and compare these values with the ones computed by script. for ex: say var.txt contains the variable names and their values: one 1 two 2 three 3 The value of variables "one" "two" and "three" will be computed in the script... (3 Replies)
Discussion started by: bhushana
3 Replies

5. Shell Programming and Scripting

How to Read different values from external file?

Hi , I am new to this scripting , I am facing an issue like how to read different values from external file by using different variables, In script I supposed to declare var 1 var 2 var 3 I know how to call this variables from external file (I am using awk command by giving same... (3 Replies)
Discussion started by: chandini
3 Replies

6. Shell Programming and Scripting

Read values from file.

I have a config file of this format: Company= Alpha Tech From Email = AlphaTech@Alphatech.com Pass = Passowrd To Email = abc@hotmail.com Smtp=smtp.live.com:587 I want to read these values from this file and use in a command to send email. I am trying grep but it gives full line. I just... (8 Replies)
Discussion started by: kashif.live
8 Replies

7. Shell Programming and Scripting

Read column values from previous and next line using awk

Hi, I have a csv file which contains data that looks something like this: Key1 Key2 Key3 New_Key1 New_Key2 New_Key3 102 30 0 - - - 102 40 1 30 40 50 102 50 2 40 50 ... (4 Replies)
Discussion started by: Nishi_Licious
4 Replies

8. Shell Programming and Scripting

Read record from the text file contain multiple separated values & assign those values to variables

I have a file containing multiple values, some of them are pipe separated which are to be read as separate values and some of them are single value all are these need to store in variables. I need to read this file which is an input to my script Config.txt file name, first path, second... (7 Replies)
Discussion started by: ketanraut
7 Replies

9. Shell Programming and Scripting

awk file to read values from Db2 table replacing hard coded values

Hi, I want to replace a chain of if-else statement in an old AWK file with values from Db2 table or CSV file. The part of code is below... if (start_new_rec=="true"){ exclude_user="false"; user=toupper($6); match(user, "XXXXX."); if (RSTART ==2 ) { ... (9 Replies)
Discussion started by: asandy1234
9 Replies

10. UNIX for Beginners Questions & Answers

awk GSUB read field values from multiple text files

My program run without error. The problem I am having. The program isn't outputting field values with the column headers to file.txt. Each of the column headers in file.txt has no data. MEMSIZE SECOND SASFoundation Filename The output results in file.txt should show: ... (1 Reply)
Discussion started by: dellanicholson
1 Replies
svsematest(8)															     svsematest(8)

NAME
svsematest - Start two threads or fork two processes and measure the latency of SYSV semaphores SYNTAX
svsematest [-a|-a PROC] [-b USEC] [-d DIST] [-f] [-i INTV] [-l loops] [-p PRIO] [-t|-t NUM] DESCRIPTION
The program svsematest starts two threads or, optionally, forks two processes that are synchronized via SYSV semaphores and measures the latency between releasing a semaphore on one side and getting it on the other side. OPTIONS
-a, --affinity[=PROC] Run on procesor number PROC. If PROC is not specified, run on current processor. -b, --breaktrace=USEC Send break trace command when latency > USEC. This is a debugging option to control the latency tracer in the realtime preemption patch. It is useful to track down unexpected large latencies of a system. -d, --distance=DIST Set the distance of thread intervals in microseconds (default is 500 us). When cylictest is called with the -t option and more than one thread is created, then this distance value is added to the interval of the threads: Interval(thread N) = Interval(thread N-1) + DIST -f, --fork Instead of creating threads (which is the default), fork new processes -i, --interval=INTV Set the base interval of the thread(s) in microseconds (default is 1000 us). This sets the interval of the first thread. See also -d. -l, --loops=LOOPS Set the number of loops. The default is 0 (endless). This option is useful for automated tests with a given number of test cycles. svsematest is stopped once the number of timer intervals has been reached. -p, --prio=PRIO Set the priority of the process. -t, --threads[=NUM] Set the number of test threads (default is 1, if this option is not given). If NUM is specified, create NUM test threads. If NUM is not specifed, NUM is set to the number of available CPUs. EXAMPLES
The following example was running on a 4-way CPU: # svsematest -a -t -p99 -i100 -d25 -l1000000 #0: ID13110, P99, CPU0, I100; #1: ID13111, P99, CPU0, Cycles 1000000 #2: ID13112, P98, CPU1, I125; #3: ID13113, P98, CPU1, Cycles 813573 #4: ID13114, P97, CPU2, I150; #5: ID13115, P97, CPU2, Cycles 667285 #6: ID13116, P96, CPU3, I175; #7: ID13117, P96, CPU3, Cycles 591403 #1 -> #0, Min 1, Cur 2, Avg 2, Max 12 #3 -> #2, Min 1, Cur 3, Avg 2, Max 12 #5 -> #4, Min 1, Cur 3, Avg 3, Max 12 #7 -> #6, Min 1, Cur 2, Avg 3, Max 11 AUTHORS
Carsten Emde <C.Emde@osadl.org> SEE ALSO
semop(2) 0.1 svsematest(8)
All times are GMT -4. The time now is 09:32 AM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy