Hi All,
I have one sensor output(over the same) for a set value of 20.
Time(in Sec), Data
1, 16
2, 20
3, 24
4, 22
5, 21
6, 20
7, 19.5
8, 20
9, 20.5
10, 20
11, 20
12, 19.5
Here we can see like after 5 sec of time the data value reaches to 20+-0.5 range.
So I want a script to print the values (my output)
6, 20
7, 19.5
8, 20
9, 20.5
10, 20
11, 20
12, 19.5
in this case.
The strict requirement here is we should skip the data data point 20 that comes after 2sec. (Sometimes even multiple entries of 20 followed by some value which is not in the rnage of 20+-0.5.
I tried the script
awk -F, '$2<=20.5 && $2 >=19.5' input.csv
but this doesn't give my required output.
Thanks
Sidda
What is your required output?
That awk script will give you the output listed.
Hi Elixir,
The required output is different than what we get from
awk -F, '$2<=20.5 && $2 >=19.5' input.csv
I request you to look into the output once more.
I don't need the second line
2, 20
in my output.
Basically I need the last portion of the data column where it is falling within my setvalue. If there are any transients in between before the data settles down we need to ignore those entries.
I hope I made much clear now.
Regards
Sidda
OK. Sorry for being a dumbo :o
awk -F, '{
if($2>=19.5 && $2<=20.5)
all=all?(all RS $0):$0
else
all=""} END{print all}' infile
awk -F"," 'BEGIN{i=1}{if($2<=20.5 && $2 >=19.5){a=$0;i++}else{i=1}}END{for(j=1;j<i;j++){print a[j]}}' infile
Hi Elixir,
Thanks a lot for replying back with the code.
But when I run this code I did not get any output.
I am unable to figure out the logic on why no output at all.
Can you please check the logic again ?
Regards
Sidda
i had tested this on your data and i got the below output
6, 20
7, 19.5
8, 20
9, 20.5
10, 20
11, 20
12, 19.5
logic is i am storing the value in an array for values in the range 20+-0.5 if the values does not lie in the range i am resetting the array index i=1.
so in the end i will get last set of values in the required range
Can you post the full contents of the input file if it's not huge?