Please I need to rearrange data acquired by USB port from a sensor network. The information is mixed and I need to convert it into a kind of table. This is my input file:
Node 4D5A joined
Temperature: 27,5
Humidity: 40
Dew Point: 23
No motion detected
LUX: 389
Temperature: 28
Humidity: 41
Dew Point: 21
Node 58DF joined
Temperature: 28,5
Humidity: 41
Dew Point: 24
LUX: 384
Node 4D5A joined
Temperature: 21,5
Humidity: 43
Dew Point: 20
No motion detected
Realize that every time a node send info, first is sent its ID and later different data without any specific pattern. My idea is to identify every line between Node and Node and arrange them into other file. Any pattern is posible... but I don't have any idea on how to implement it. I have been trying with awk, sed, grep... but with no result.
You may need to change it a bit if you want to remove blanks for values or filter out unwanted lines (maybe you don't need the message "No motion detected", I don't know):
Basically, we first need to know which node every information in the input file is related to and then, given the node name and the measurement name, populate an associative array (hash) which keys are the concatenation between "node_name:measurement_name". For each element, the associated value will be the union of all the consecutive values found, separated by "/".
We once tell awk that the Output Field Separator for print statements will be a colon:
For each row of the file, we execute the code between curly braces. Here, when we notice that the first space-separated field of the file corresponds to the word "Node", we assign to the "n" variable the node name (=2nd field, $2):
If that's not the case, we elaborate the measurement information. By the means of split function, we create an array called "x" which will contain the two colon-separated fields: x[1] is the measurement name (eg. "Temperature"), x[2] is the measurement value (eg. " 27,5"):
Now we compose a key for our hash, concatenating "n" (eg. "4D5A"), a colon ":" and the measurement name.
For example, in the second loop, our key will be "4D5A:Temperature", in the 3rd "4D5A:Humidity" and so on.
The corresponding value for the key just found will be the measurement value, x[2]. Here I've used a ternary operator because you want to display "0" even if the measurement name hasn't an associated value, for example in the case of "No motion detected": if x[2] is not null, val=x[2], else val=" 0".
Now that we have defined the key and the value, we populate an associative array called "y".
There's another ternary operator: if an element associated with the key is already present, the value will be the actual non-null value (y[key]) followed by a slash " /" and the measurement value (val); if it is the first time we insert a value for the key "key", we don't put the slash.
Finally, when all the hash is populated with the values got from every record of the input file, we simply print all the key/value pairs. The print output is OFS delimited.
The awk result is piped through the "sort" command to beautify and make readable the output
Hello.
System : opensuse leap 42.3
I have a bash script that build a text file.
I would like the last command doing :
print_cmd -o page-left=43 -o page-right=22 -o page-top=28 -o page-bottom=43 -o font=LatinModernMono12:regular:9 some_file.txt
where :
print_cmd ::= some printing... (1 Reply)
How to use "mailx" command to do e-mail reading the input file containing email address, where column 1 has name and column 2 containing “To” e-mail address
and column 3 contains “cc” e-mail address to include with same email.
Sample input file, email.txt
Below is an sample code where... (2 Replies)
Hi, everyone.
I need to write a program to get io info based on libperfstat.
But the "write time" of a disk is just half of the value get from iostat.
I'm confused and can't explain. Help please.
How I calculate "write service time per sec":
In iostat:
write service... (0 Replies)
Hi all.
I have a .txt file that I need to sort it
My file is like:
1- 88 chain0 MASTER (FF-TE) FFFF 1962510 /TCK T FD2TQHVTT1 /jtagc/jtag_instreg/updateinstr_reg_1 dff1 (TI,SO)
2- ... (10 Replies)
Hi,
I have line in input file as below:
3G_CENTRAL;INDONESIA_(M)_TELKOMSEL;SPECIAL_WORLD_GRP_7_FA_2_TELKOMSEL
My expected output for line in the file must be :
"1-Radon1-cMOC_deg"|"LDIndex"|"3G_CENTRAL|INDONESIA_(M)_TELKOMSEL"|LAST|"SPECIAL_WORLD_GRP_7_FA_2_TELKOMSEL"
Can someone... (7 Replies)
Hi,
I'm seeing the error vmunix: file: table is full in syslog.log.
Although changing the value of the kernel parameter nfile would make this error go away, how would I identify which process/application in the server is triggering this error? The server is a HP-UX B.11.11.
Thanks in advance! (1 Reply)
Hi Friends,
Can any of you explain me about the below line of code?
mn_code=`env|grep "..mn"|awk -F"=" '{print $2}'`
Im not able to understand, what exactly it is doing :confused:
Any help would be useful for me.
Lokesha (4 Replies)
I HAVE A FILE "TEXT.TXT" WHICH CONTAINS FOLLOWING :
CHANNEL(SYSTEM.DEF.CLUSRCVR) CHLTYPE(CLUSRCVR)
CHANNEL(TO.XYZ) CHLTYPE(CLUSRCVR)
NOW I WANT THE NAMES WRITTEN BETWEEN THE BRACES () UNDER COLUMN ONE, THAT IS, TO.XYZ and SYSTEM.DEF.CLUSRCVR.... (10 Replies)