Shell script to read little complex values


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Shell script to read little complex values
# 1  
Old 09-04-2014
Shell script to read little complex values

Dear All,

I have attached a file. In that I want to read some of the values like
1. ExecutionTime
2. ClockTime
etc. I want to read at a specified time. How can I do that?

Thanks & Regards,
linuxUser_
# 2  
Old 09-04-2014
What have you tried?
# 3  
Old 09-05-2014
Code:
grep -r -n "Time = " fileName

will give me all the time data.... but I really dont have any idea how to capture specific time or loop over all times.

If I can loop over all the times also completely fine. I have my own logic to solve the issue.
# 4  
Old 09-05-2014
What output are you trying to get?
# 5  
Old 09-05-2014
As you are running the grep directly on a file name you do not need the -r option which is for searching directories recursively.

What are your EXACT requirements? Like what is your desired output and specifically what are you trying to do?
# 6  
Old 09-05-2014
you can change the value of t to wharever time you wanted to grep
Code:
awk '$0 ~ ("^Time = " t "$") {getline;
 for(i=1; i<=NF; i++)
  {if($i ~ /^ExecutionTime$/) et=($(i+2) " " $(i+3))
  else if($i ~ /ClockTime/) ct=($(i+2) " " $(i+3))}
 print "Time = " t
 print "ExecutionTime = " et
 print "ClockTime = " ct}' RS= FS='[ \t\n]' t='0.639' logRun.txt

This User Gave Thanks to SriniShoo For This Post:
# 7  
Old 09-06-2014
Quote:
Originally Posted by pilnet101
As you are running the grep directly on a file name you do not need the -r option which is for searching directories recursively.

What are your EXACT requirements? Like what is your desired output and specifically what are you trying to do?
Hi

Thanks for reply.
My exact requirement is to read a variable form file. Everything else I can manage.

lets say I have a file with following entities.
file.txt
Code:
Heroname Hrithik;
heroAge 19;
lastMarriedGalsAge 35.54312;

Now I want to read this data using shell and do something else.

How can I do that?

My trails:
Code:
awk -v '
        /^Heroname/ {SF=$2;gsub(";$"," ",SF)}
        /^heroAge/ {ST=$2;gsub(";$"," ",ST)}
        /^lastMarriedGalsAge/ {SA=$2;gsub(";$"," ",SA)}
       ' file.txt
echo $SF;
echo $ST;
echo $SA;

result
Code:
awk: improper assignment: -v

Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Read a file and replace values in a script

Hi , I have a property file placed in folder /usr/opt/temp/aorc.prop which has values given below . I need to read this file content and replace the node with actual values in a shell script . Each time the script shall replace the node value from the poperty file and execute a cfsend command and... (10 Replies)
Discussion started by: samrat dutta
10 Replies

2. Shell Programming and Scripting

Read in shell variable values from a file

Hello, I have a simple script that runs an application, # these arguments have the same value for all splits ARCH=12.11.1 BATCHES=50 EPOCHS=5000 LEARN_MODE=ONLINE LEARN_RATE=0.25 PROJ=02_BT_12.11.1.proj echo "processing split A on hex" cd A/ DATA_SET=S2A_v1_12.1.1_1... (4 Replies)
Discussion started by: LMHmedchem
4 Replies

3. Shell Programming and Scripting

Complex calulation in shell script

Hi , I need one help to do some complex calculation in shell script. here is what i need to do:- a=2 b=2 c=2 d=2 result=a+(b/(20*c))+(c/(10*d)) is there any thing special there so that i can group intermdiate results. Please help me if you have any idea. (4 Replies)
Discussion started by: harpal singh
4 Replies

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

5. Shell Programming and Scripting

Change col to row using shell script..Very Complex

Hi guys I have file A with Below Data ABC123 X1 X2 X3 ABC123 Y1 Y33 Y4 ABC123 Z1 ZS2 ZL3 ABC234 P1 PP3 PP9 ABC234 Q1 ABC234 R1 P09 PO332 PO331 OKI12 .. .. .. Now I want file B as below ABC123 X1 X2 X3;Y1 Y33 Y4;Z1 ZS2 ZL3 ABC234 P1 PP3 PP9;Q1;R1 P09 PO332 PO331 OKI12... (1 Reply)
Discussion started by: asavaliya
1 Replies

6. Shell Programming and Scripting

Help with script to read lines from file and count values

Hi, I need some help with a script I'm trying to write. I have a log file containing references to a number of different webservices. I wish to write a script that will list the webservices with a count as to how many times they appear in the log. An example of the log file content: ... (2 Replies)
Discussion started by: gman2010
2 Replies

7. Shell Programming and Scripting

How can I read values from a CSV file using Shell?

SHELL SCRIPT Hi, I have a file in which contents are as follows: 9999,abdc,123 9988,aba_12,2323 and so on I want to read the contents of this file such that i can do echo "This is $a followed by $b an then $c" I tried the following but id did not work cat test | cut -d ',' -f1|... (7 Replies)
Discussion started by: mayanksargoch
7 Replies

8. Shell Programming and Scripting

how can i read text file and assign its values to variables using shell

Hello, I have a cat.dat file, i would like shell to read each 3 lines and set this 3 lines to 3 different variables. my cat.dat is: 11 12 +380486461001 12 13 +380486461002 13 14 +380486461003 i want shell to make a loop and assign 1st line to student_id, 2nd line to... (4 Replies)
Discussion started by: rosalinda
4 Replies

9. Shell Programming and Scripting

How to read values that are passed to the shell function in ksh.

In ksh shell, There is a function f1. function f1 { How to read here?? .... .... } I am passing values to fuunction f1 as f1 "A" "B" Please tell me how to read the passed values in function f1. Advance Thanks & Regards Prashant (2 Replies)
Discussion started by: prashant43
2 Replies

10. Shell Programming and Scripting

Korn Shell Script - Read File & Search On Values

I am attempting to itterate through a file that has multiple lines and for each one read the entire line and use the value then to search in other files. The problem is that instead of an entire line I am getting each word in the file set as the value I am searching for. For example in File 1... (2 Replies)
Discussion started by: run_unx_novice
2 Replies
Login or Register to Ask a Question