using awk iteratively in a script to assign variable values
I have a log file that has certain fields that I want to evaluate, and depending on the value in those fields, I want to put the value of a different field in that line in a particular variable that I'll use later on down the log file. Sort of like setting a switch to change what I do with a bunch of lines I've been saving as I go through the log. The log file looks something like this:
I want to put all the lines between the line that has "start" and the line that has "bad_trial" into a new text file, with each line stripping out everything but the first entry ("blah") and the number, e.g. the new file will look like:
[followed by other sets of lines between "start" and "bad_trial" lines].
Ultimately I want to append these lines to another file, for later evaluation in a different program.
I've gotten so far as to have the script read in the file line by line and use awk to check for values in each line, and if it finds them, put the number in a variable (that I was going to use to write out to a new file). But when I have it put things in a variable, it seems to just keep adding values to the end of the existing values in that variable, rather than replacing the existing value. Here is what I have:
(I know this doesn't do what my ultimate goal is, I'm just trying to get there in baby steps)
The value of $trial_type at the end of this is a string of numbers separated by spaces, in which the numbers are the values in the 4th field for all the lines that have "bad_trial" in them. What I want to have happen in this simple script instead is to replace the value of $trial_type, not append it to the existing value of $trial_type.
Any ideas for what I'm doing wrong, and/or suggestions for how to get to my ultimate goal, please let me know! And thanks for reading this far.
-Tom
Moderator's Comments:
Use code tags please, got a PM. Can also open this post in edit mode and see what tags I inserted, thanks.
Last edited by zaxxon; 11-02-2011 at 05:49 AM..
Reason: code tags, see PM
Hi Gurus,
I have a script which assign awk output to shell variable. current it uses two awk command to assign value to two variables. I want to use one command to assign two values to two variables. I tried the code, but it does't work. kindly provide your suggestion.
current code... (2 Replies)
I have the following script, and I want to assign the output ($10 and $5) from awk to N and L:
grdinfo data.grd | awk '{print $10,$5}'| read N L
output from gridinfo data.grd is: data.grd 50 100 41 82 -2796 6944 0.016 0.016 3001 2461. where N and L is suppose to be 3001 and 100. I use... (8 Replies)
Hello,
Could anyone please help me with Assigning a value to variable and then updating the value in the original file
IFS='|'
while read -r Serial_ID JOB_NAME STATUS
do
if
then
echo "Perform Fuctions"
???Assign STATUS to COMPLETED and Update File???
done <File (7 Replies)
Hi All,
I wrote a database command that queries our application and outputs a whole bunch of values to a text file. I need to assign the output to two values.
Here is a sample of the output:
valueOne, checkOne
valueTwo, checkTwo
valueThree, checkThree
I would like... (9 Replies)
Hi i have one variable like DIR="f1 f2" in config file
in my script i have one runtime variable LFILE="DIR"
now i want to use $DIR in my script by using LFILE that is i dont want to use DIR dirctly i am extracting DIR by some other means.
Config file : DIR="f1 f2"
Script:
LFILE="DIR"
i... (3 Replies)
Hi,
I have a text file with multiple lines, each having data in the below format <DOB>,<ADDRESS>
I have to write a script which reads each line in the text file in loop, assign the values to these variables and do some further processing in it.
Using the following code prints the values... (12 Replies)
Hi Masters,
I want to assign the values of one variable to another variable.
Here the varaible name 'var' is dynamic. I know the values of V_2 and U_3, but
If the i/p of TYPE is 'U' and the NO is 3, then I want to assign the values of
U_3 to var.
How we can achieve it?
TYPE="U"... (4 Replies)
Dear All,
we have a command output which looks like :
Total 200 queues in 30000 Kbytes
and we're going to get "200" and "30000" for further process. currently, i'm using :
numA=echo $OUTPUT | awk '{print $2}'
numB=echo $OUTPUT | awk '{print $5}'
my question is : can I use just one... (4 Replies)
I have a csv file with the values seperated by commas.I want to extract these values one by one and assign to a variable using shell script.Any ideas or code? (11 Replies)
i have a file in this format
curyymm PRVYYMM CDDMmmYY bddMmmyy eddMmmyy
--------- ------- ------------ ---------- -----------
0906 0905 09Jun09 01Jun09 30Jun09
----------- --------- ------------ ------------ -----------
i need to read the... (5 Replies)