I'm trying to query my customlogs table (Eg: CustomData_CL) by giving the time range. The result of this query will be the filtered time ranged data. I want to find out the data size of the resulted output.
Query which I have used to fetch the time ranged o/p:
CustomData_CL
| where TimeGenerated between (datetime(2022–09–14 04:00:00) .. datetime(2020–09–14 05:00:00))
But it is giving the following error:
Can anyone please suggest on the same ?
Note the characters with code point 8211.
These are not standard hyphens (-) 🙂.
let p_str = "(datetime(2022–09–14 04:00:00) .. datetime(2020–09–14 05:00:00))";
print str = p_str
| mv-expand str = extract_all("(.)", str) to typeof(string)
| extend dec = to_utf8(str)[0]
str
dec
(
40
d
100
a
97
t
116
e
101
t
116
i
105
m
109
e
101
(
40
2
50
0
48
2
50
2
50
–
8211
0
48
9
57
–
8211
1
49
4
52
32
0
48
4
52
:
58
0
48
0
48
:
58
0
48
0
48
)
41
32
.
46
.
46
32
d
100
a
97
t
116
e
101
t
116
i
105
m
109
e
101
(
40
2
50
0
48
2
50
0
48
–
8211
0
48
9
57
–
8211
1
49
4
52
32
0
48
5
53
:
58
0
48
0
48
:
58
0
48
0
48
)
41
)
41
Fiddle
Update, per OP request:
Please note that in addition to the use of a wrong character that caused the syntax error, your 2nd datetime year was wrong.
// Generation of mock table. Not part of the solution
let CustomData_CL = datatable(TimeGenerated:datetime)[datetime(2022-09-14 04:30:00)];
// Solution starts here
CustomData_CL
| where TimeGenerated between (datetime(2022-09-14 04:00:00) .. datetime(2022-09-14 05:00:00))
TimeGenerated
2022-09-14T04:30:00Z
Fiddle
I'm preparing the material for a KQL course, and I thought about creating a challenge, based on your question.
Check out what happened when I posted your code into Kusto Web Explorer... 🙂
How cool is that?!
I develop a CGI in bash/html.
With this CGI, I'm able to display some informations from csv files.
One of theses informations is the consumption in RAM and CPU of different FRAME.
To display these informations, I create this page :
#!/bin/bash
echo "Content-type: text/html"
echo ""
echo '
<html>
<head>
<meta http-equiv="Content-Type" content="test/html"; charset=UTF-8">
<title> CLF MONITORING </title>
<h1> FRAME monitoring <font size=3> [ Index ] </font> </h1>
<hr size="4" color="blue">
<style>
body{
background-color: #eff1f0;
}
</style>
</head>
<body>'
echo "<table>"
echo "<tr>"
echo "<td>"
echo "<PRE>"
echo "`./FRAME_SCRIPT.sh cccc.csv bbbb.csv`"
echo "</td>"
echo "</tr>"
echo "</PRE>"
echo "</table>"
echo '</body>'
'</html>'
My script " FRAME_SCRIPT.sh " display informations about FRAME from different csv files. Here the script
#!/bin/bash
OLDIFS=$IFS
IFS=','
for arg
do
echo -e "File : $arg "
echo "======================================================="
echo ""
while read FRAME RAM CPU1 CPU2
do
if [[ $FRAME != $PREV ]]
then
PREV=$FRAME
echo "FRAME : $FRAME"
echo -e "-----------------\n"
fi
echo -e "RAM : \t$RAM\n\
CPU 1 :\t$CPU1\n\
CPU 2 :\t$CPU2\n"
echo ""
done < "$arg"
done
I run it with the command :
./My_script.sh *.csv
The output is :
File : cccc.csv
=======================================================
FRAME : MIAIBB00
-----------------
RAM :
CPU 1 :
CPU 2 :
FRAME : MIAIBTST1
-----------------
RAM :
CPU 1 :
CPU 2 :
FRAME : MIAIBYC00
-----------------
RAM : 8
CPU 1 : 2.0
CPU 2 : 4
RAM : 5
CPU 1 : 0.1
CPU 2 : 1
RAM : 6
CPU 1 : 0.2
CPU 2 : 1
RAM : 0.25
CPU 1 : 0.2
CPU 2 : 1
RAM : 64
CPU 1 : 3.0
CPU 2 : 7
RAM : 80
CPU 1 : 20.0
CPU 2 : 20
RAM : 8
CPU 1 : 1.0
CPU 2 : 2
RAM : 4
CPU 1 : 1.0
CPU 2 : 2
RAM : 4
CPU 1 : 1.0
CPU 2 : 2
RAM : 0
CPU 1 : null
CPU 2 : 0
File : bbbb.csv
=======================================================
FRAME : MO1PPC02
-----------------
RAM : 12
CPU 1 : 0.3
CPU 2 : 2
RAM : 8
CPU 1 : 0.2
CPU 2 : 2
RAM : 15
CPU 1 : 0.8
CPU 2 : 2
RAM : 8
CPU 1 : 0.5
CPU 2 : 1
RAM : 36
CPU 1 : 2.0
CPU 2 : 4
RAM : 48
CPU 1 : 8.0
CPU 2 : 12
RAM : 8
CPU 1 : 0.2
CPU 2 : 2
RAM : 8
CPU 1 : 0.2
CPU 2 : 2
RAM : 31
CPU 1 : 2.0
CPU 2 : 8
But on my web page I would like to display the informations like that :
The idea is when everytime the pattern " File : XXXXX " appears, this patterns with his own informations is displayed in a new column, next to the previous patterns " File : XXXX ".
I think if we use the " File : " like the key pattern, it's possible. I can't use the name of the file because it's never the same one. Maybe it's possible to do this, but I don't know how...
In my exemple, I run my script in a directory with only 2 csv files, but in reality, I have a lot more csv files. So in this case, I use only 2 csv to be more clearly.
Do you have any idea to do this ?
Don't use shell loops to manipulate text (see why-is-using-a-shell-loop-to-process-text-considered-bad-practice).
If I were you I'd format the output as an HTML table rather than pre-formatted text but just follow the steps below to see one way to get the output you want:
$ cat ../tst.awk
BEGIN {
FS = ","
OFS = " : "
split("FRAME,RAM,CPU 1,CPU 2", titles)
}
FNR == 1 {
close(out)
out = "out" ++cnt ".txt"
print "File", FILENAME ORS "====================" > out
}
$1 != prev {
print "" ORS fmt(1) "\n--------------------\n" > out
prev = $1
}
{
for (i=2; i<=NF; i++) {
print fmt(i) > out
}
print "" > out
}
function fmt(fldNr) { return sprintf("%-8s%s", titles[fldNr] OFS, $fldNr) }
.
$ ls
bbbb.csv cccc.csv
.
$ tail -n +1 *.csv
==> bbbb.csv <==
MO1PPC02,12,0.3,2
MO1PPC02,8,0.2,2
MO1PPC02,15,0.8,2
MO1PPC02,8,0.5,1
MO1PPC02,36,2.0,4
MO1PPC02,48,8.0,12
MO1PPC02,8,0.2,2
MO1PPC02,8,0.2,2
MO1PPC02,31,2.0,8
==> cccc.csv <==
MIAIBB00,,,
MIAIBTST1,,,
MIAIBYC00,8,2.0,4
MIAIBYC00,5,0.1,1
MIAIBYC00,6,0.2,1
MIAIBYC00,0.25,0.2,1
MIAIBYC00,64,3.0,7
MIAIBYC00,80,20.0,20
MIAIBYC00,8,1.0,2
MIAIBYC00,4,1.0,2
MIAIBYC00,4,1.0,2
MIAIBYC00,0,null,0
.
$ awk -f ../tst.awk cccc.csv bbbb.csv
.
$ ls
bbbb.csv cccc.csv out1.txt out2.txt
.
$ tail -n +1 *.txt
==> out1.txt <==
File : cccc.csv
====================
FRAME : MIAIBB00
--------------------
RAM :
CPU 1 :
CPU 2 :
FRAME : MIAIBTST1
--------------------
RAM :
CPU 1 :
CPU 2 :
FRAME : MIAIBYC00
--------------------
RAM : 8
CPU 1 : 2.0
CPU 2 : 4
RAM : 5
CPU 1 : 0.1
CPU 2 : 1
RAM : 6
CPU 1 : 0.2
CPU 2 : 1
RAM : 0.25
CPU 1 : 0.2
CPU 2 : 1
RAM : 64
CPU 1 : 3.0
CPU 2 : 7
RAM : 80
CPU 1 : 20.0
CPU 2 : 20
RAM : 8
CPU 1 : 1.0
CPU 2 : 2
RAM : 4
CPU 1 : 1.0
CPU 2 : 2
RAM : 4
CPU 1 : 1.0
CPU 2 : 2
RAM : 0
CPU 1 : null
CPU 2 : 0
==> out2.txt <==
File : bbbb.csv
====================
FRAME : MO1PPC02
--------------------
RAM : 12
CPU 1 : 0.3
CPU 2 : 2
RAM : 8
CPU 1 : 0.2
CPU 2 : 2
RAM : 15
CPU 1 : 0.8
CPU 2 : 2
RAM : 8
CPU 1 : 0.5
CPU 2 : 1
RAM : 36
CPU 1 : 2.0
CPU 2 : 4
RAM : 48
CPU 1 : 8.0
CPU 2 : 12
RAM : 8
CPU 1 : 0.2
CPU 2 : 2
RAM : 8
CPU 1 : 0.2
CPU 2 : 2
RAM : 31
CPU 1 : 2.0
CPU 2 : 8
.
$ paste *.txt
File : cccc.csv File : bbbb.csv
==================== ====================
FRAME : MIAIBB00 FRAME : MO1PPC02
-------------------- --------------------
RAM : RAM : 12
CPU 1 : CPU 1 : 0.3
CPU 2 : CPU 2 : 2
RAM : 8
FRAME : MIAIBTST1 CPU 1 : 0.2
-------------------- CPU 2 : 2
RAM : RAM : 15
CPU 1 : CPU 1 : 0.8
CPU 2 : CPU 2 : 2
RAM : 8
FRAME : MIAIBYC00 CPU 1 : 0.5
-------------------- CPU 2 : 1
RAM : 8 RAM : 36
CPU 1 : 2.0 CPU 1 : 2.0
CPU 2 : 4 CPU 2 : 4
RAM : 5 RAM : 48
CPU 1 : 0.1 CPU 1 : 8.0
CPU 2 : 1 CPU 2 : 12
RAM : 6 RAM : 8
CPU 1 : 0.2 CPU 1 : 0.2
CPU 2 : 1 CPU 2 : 2
RAM : 0.25 RAM : 8
CPU 1 : 0.2 CPU 1 : 0.2
CPU 2 : 1 CPU 2 : 2
RAM : 64 RAM : 31
CPU 1 : 3.0 CPU 1 : 2.0
CPU 2 : 7 CPU 2 : 8
RAM : 80
CPU 1 : 20.0
CPU 2 : 20
RAM : 8
CPU 1 : 1.0
CPU 2 : 2
RAM : 4
CPU 1 : 1.0
CPU 2 : 2
RAM : 4
CPU 1 : 1.0
CPU 2 : 2
RAM : 0
CPU 1 : null
CPU 2 : 0
.
$ paste *.txt | column -L -s$'\t' -t
File : cccc.csv File : bbbb.csv
==================== ====================
FRAME : MIAIBB00 FRAME : MO1PPC02
-------------------- --------------------
RAM : RAM : 12
CPU 1 : CPU 1 : 0.3
CPU 2 : CPU 2 : 2
RAM : 8
FRAME : MIAIBTST1 CPU 1 : 0.2
-------------------- CPU 2 : 2
RAM : RAM : 15
CPU 1 : CPU 1 : 0.8
CPU 2 : CPU 2 : 2
RAM : 8
FRAME : MIAIBYC00 CPU 1 : 0.5
-------------------- CPU 2 : 1
RAM : 8 RAM : 36
CPU 1 : 2.0 CPU 1 : 2.0
CPU 2 : 4 CPU 2 : 4
RAM : 5 RAM : 48
CPU 1 : 0.1 CPU 1 : 8.0
CPU 2 : 1 CPU 2 : 12
RAM : 6 RAM : 8
CPU 1 : 0.2 CPU 1 : 0.2
CPU 2 : 1 CPU 2 : 2
RAM : 0.25 RAM : 8
CPU 1 : 0.2 CPU 1 : 0.2
CPU 2 : 1 CPU 2 : 2
RAM : 64 RAM : 31
CPU 1 : 3.0 CPU 1 : 2.0
CPU 2 : 7 CPU 2 : 8
RAM : 80
CPU 1 : 20.0
CPU 2 : 20
RAM : 8
CPU 1 : 1.0
CPU 2 : 2
RAM : 4
CPU 1 : 1.0
CPU 2 : 2
RAM : 4
CPU 1 : 1.0
CPU 2 : 2
RAM : 0
CPU 1 : null
CPU 2 : 0
Hello I am writing a code using pthread_cond_wait() and pthread_cond_broadcast(). The objective of my code is to trigger four threads at a time which should run in parallel.When I am passing signal to four threads using pthread_cond_broadcast all the four are getting triggered serially.The triggered time for the four threads are as given below.
HH : MM : SS : MS : uS
Thread 1 12 : 59 : 05 : 27 : 407
Thread 2 12 : 59 : 05 : 27 : 586
Thread 3 12 : 59 : 05 : 27 : 879
Thread 4 12 : 59 : 05 : 28 : 113
From the observation we can see that triggered time of four threads are varying so can anyone tell me what is the reason for that?
I wonder why this code gives runtime error. http://ideone.com/4a7v5A
I tried it on my local as well this is how I compile
g++ -pthread -Wl,--no-as-needed -c -g -std=c++11 -MMD -MP -MF "/tmp/main.o.d" -o /tmp/main.o main.cpp
mkdir -p dist/Debug/GNU-Linux-x86
g++ -pthread -Wl,--no-as-needed -o /tmp/main.o -pthread
This is the code in the link
And this is the output
1 : Consumer-0joining
2 : Procuding item 1
3 : finished
4 : Consumer-5 consuming item 1
5 : Consumer-5 0 item left
6 : Procuding item 1
7 : finished
8 : Consumer-4 consuming item 1
9 : Consumer-4 0 item left
10 : Procuding item 1
11 : finished
12 : Consumer-2 consuming item 1
13 : Consumer-2 0 item left
14 : Procuding item 1
15 : finished
16 : Consumer-0 consuming item 1
17 : Consumer-0 0 item left
18 : Procuding item 1
19 : finished
20 : Consumer-6 consuming item 1
21 : Consumer-6 0 item left
22 : Procuding item 1
23 : finished
24 : Consumer-3 consuming item 1
25 : Consumer-3 0 item left
26 : Procuding item 1
27 : finished
28 : Consumer-1 consuming item 1
29 : Consumer-1 0 item left
30 : Procuding item 1
31 : finished
32 : Consumer-5 consuming item 1
33 : Consumer-5 0 item left
terminate called after throwing an instance of 'std::system_error'
what(): Operation not permitted
I have three files with different column and row size. For example,
ifile1.txt ifile2.txt ifile3.txt
1 2 2 1 6 3 8
2 5 6 3 8 9 0
3 8 7 6 8 23 6
6 7 6 23 6 44 5
9 87 87 44 7 56 7
23 6 6 56 8 78 89
44 5 76 99 0 95 65
56 6 7 99 78
78 7 8 106 0
95 6 7 110 6
99 6 4
106 5 34
110 6 4
Here ifile1.txt has 3 coulmns and 13 rows,
ifile2.txt has 2 columns and 7 rows,
ifile3.txt has 2 columns and 10 rows.
1st column of each ifile is the ID,
This ID is sometimes missing in ifile2.txt and ifile3.txt.
I would like to make an outfile.txt with 4 columns whose 1st column would have all the IDs as in ifile1.txt, while the 2nd coulmn will be $3 from ifile1.txt, 3rd and 4th column will be $2 from ifile2.txt and ifile3.txt and the missing stations in ifile2.txt and ifile3.txt will be assigned as a special charecter '?'.
Desire output:
outfile.txt
1 2 6 ?
2 6 ? ?
3 7 8 8
6 6 8 ?
9 87 ? 0
23 6 6 6
44 76 7 5
56 7 8 7
78 8 ? 89
95 7 ? 65
99 4 0 78
106 34 ? 0
110 4 ? 6
I was trying with the following algorithm, but can't able to write a script.
for each i in $1, awk '{printf "%3s %3s %3s %3s\n", $1, $3 (from ifile1.txt),
check if i is present in $1 (ifile2.txt), then
write corresponding $2 values from ifile2.txt
else write ?
similarly check for ifile3.txt
You can do that with GNU AWK using this script:
script.awk
# read lines from the three files
ARGIND == 1 { file1[ $1 ] = $3
# init the other files with ?
file2[ $1 ] = "?"
file3[ $1 ] = "?"
next;
}
ARGIND == 2 { file2[ $1 ] = $2
next;
}
ARGIND == 3 { file3[ $1 ] = $2
next;
}
# output the collected information
END { for( k in file1) {
printf("%3s%6s%6s%6s\n", k, file1[ k ], file2[ k ], file3[ k ])
}
}
Run the script like this: awk -f script.awk ifile1.txt ifile2.txt ifile3.txt > outfile.txt