Hi!
I have 2 files containing data that I need to process at the same time, I have problems in reading a different number of lines from the different files.
Here is an explanation of what I need to do (possibly with an awk script).
File "samples.txt" contains data in the format:
time_instant measure
HTML Code:
903.0 -
906.43 18.4
912.7 17.5
918.05 11.2
File "time.txt" contains data in the format
time_instant position
HTML Code:
900 out
901 out
902 out
903 in
904 in
905 in
906 in
907 in
908 out
909 out
910 out
911 in
912 in
913 in
I need to compute temporal averages of the measures in samples.txt, but the temporal averages must be related only to the time instants in which the position in time.txt is "in".
So, I need at the end to have:
a/b
where a=sum(measure_i*duration_measure_i)
b=total_measurement_duration
- measure_i is the second field in every line of samples.txt
- duration_measure_i is the difference between the 1st fields in two consecutive lines in samples.txt and eventually the duration of the period in which the position in time.txt was "out"
So, for example I would do for the first measurement (that is on the second line in samples.txt, since the 1st line only tells me when measurements start):
a=18.4*(906.43-903.0-0)
b=(906.43-903.0-0)
Then for the second:
a+=17.5*(912.7-906.43-2)
b+=(912.7-906.43-2)
I am quite new to awk and don't know how to read two lines at a time from samples.txt and search in time.txt the lines that are between the time instants written from samples.txt
So, for example I would do for the first measurement (that is on the second line in samples.txt, since the 1st line only tells me when measurements start):
a=18.4*(906.43-903.0-0)
b=(906.43-903.0-0)
Then for the second:
a+=17.5*(912.7-906.43-2)
b+=(912.7-906.43-2)
2 is the time spent "out".
I know that looking the file it should be 3, but for the periods when the position is "out", I have to consider as length of the period the final_time-initial_time (for example, in case only 1 consecutive line with "out" appeared, then the length of interval would be 0 and I would not subtract any time)
Then, 910-908=2
That's because my records on "out" periods are only instantaneous.. sorry for not explaining that in a clearer way in the previous post. :-)
The time intervals in the two files don't coincide: in samples.txt I record my measures, then I have to search for the related time intervals of interest in time.txt.
For example, in samples.txt, measurements started at 903.0, then at 906.43 I got the first measure (2nd line). So, I have to go in time.txt and check if in the time period between 903 and 906.43 I was "in" or "out". Since I've been "in" all the time,itì's ok and I don't need to subtract anything.
The time instants preceding this interval are discarded.
Then, I go to the second measure in samples.txt (3rd line) and check if in time.txt if in the time interval between 906.43 and 912.7 I was "in" or "out". I've been "out" for 2 seconds, so I subtract this value from the time interval duration, and so on.
Time.txt records a very long time, usually with many seconds preceding and following the time instants in which measurements were taken. I refer to samples.txt, considering one sample at every iteration (i.e. the line referring to the current measure and the preceding one in order to get the time interval of interest), then I need to get the correspondent lines related to that time interval in time.txt. If the duration of "out" periods in this interval of interest is zero, it's ok and I don't need to subtract anything. In case it's non-zero, I need to subtract it from the interval duration
Hope is much clearer, thank a lot for your help anyway!
---------- Post updated at 05:11 AM ---------- Previous update was at 04:54 AM ----------
Hope this helps. Suppose you have
and
The result I need to get is
{18.4*(906.43-903.0-0)+17.5*(912.7-906.43-2)+11.2*(921.05-912.7-3)}/{(906.43-903.0-0)+(912.7-906.43-2)+(921.05-912.7-3)}
Hi guys, I receive a list from pipe (with fixed number of lines) like this:
name1
name2
name3
And in my ./ folder I have three files:
01-oldname.test
02-someoldname.test
03-evenoldername.test
How to rename files one by one using while read?
Desired result:
01-name1.test
02-name2.test... (3 Replies)
Hi,
I'm using awk command in bash script. I'm able to pass multiple files to awk for processing.The code i can use is as below(sample code)
#!/bin/bash
awk -F "," 'BEGIN {
...
...
...
}' file1 file2 file3
In the above code i'm passing the file names manually and it is fine till my... (7 Replies)
Dear Friends,
I am in urgent need for awk/sed/sh script for converting a specific data format (.txt) to .xls.
The input is as follows:
>gi|1234|ref|
Query = 1 - 65, Target = 1677 - 1733
Score = 8.38, E = 0.6529, P = 0.0001513, GC = 46
fd sdfsdfsdfsdf
fsdfdsfdfdfdfdfdf... (6 Replies)
Hy!
I need to post-process some data files which have variable (and periodic) number of fields. For example, I need to square (data -> data*data) the folowing data file: -5.34281E-28 -3.69822E-29 8.19128E-29 9.55444E-29 8.16494E-29 6.23125E-29
4.42106E-29 2.94592E-29 1.84841E-29 ... (5 Replies)
Hello,
I extracted a list of files in a directory with the command ls . However this is not my computer, so the ls functionality has been revamped so that it gives the filesizes in front like this :
This is the output of ls command : I stored the output in a file filelist
1.1M... (5 Replies)
Hello,
I have some bitrate data in a csv which is in an odd format and is difficult to process in Excel when I have thousands of rows. Therefore, I was thinking of doing this in bash and using awk as the primary application except that due to its complication, I'm a little stuck.
... (24 Replies)
I have following result.log file (always has 2 lines) which I need to process,
cat result.log
name.cmd.method,"result","abc","xyz";
name="hello,mine.12345,"&"tree"&" xyz "&" tree "&" xyz",
data="way,"&" 1"&"rate-me"&"1"&"rate-me",str="",ret="";
now I need to extract the strings/data as... (4 Replies)
I have a file, first 5 columns are very normal, like "1107",106027,71400,"Y","BIOLOGY",,
however, the 6th columns, the user can put comments, anything, just any characters, like new line, double quote, single quote, whatever from the keyboard, like"Please load my previous SOM597G course content in... (3 Replies)
Helllo UNIX Forum :)
Since I am posting on this board, yes, I am new to UNIX!
I read a copy of "UNIX made easy" from 1990, which felt like a making a "computer-science time jump" backwards ;)
So, basically I have some sort of understanding what the basic concept is.
Problem Description:... (6 Replies)