I have many .txt file in one location. This txt content is as below.
%-ile | Read (ms) | Write (ms) | Total (ms)
----------------------------------------------
min | N/A | 0.018 | 0.018
25th | N/A | 0.055 | 0.055
50th | N/A | 0.059 | 0.059
75th | N/A | 0.062 | 0.062
90th | N/A | 0.070 | 0.070
95th | N/A | 0.073 | 0.073
99th | N/A | 0.094 | 0.094
3-nines | N/A | 0.959 | 0.959
4-nines | N/A | 67.552 | 67.552
5-nines | N/A | 75.349 | 75.349
6-nines | N/A | 84.994 | 84.994
7-nines | N/A | 85.632 | 85.632
I am reading 3-nines from above content and want to write a program like it Total (ms) column's value in greater than 1 with respect to 3-nines row it should print that file name.
For that I have written a program as below:
$data = get-content "*.txt" | Select-String -Pattern "3-nines"
$data | foreach {
$items = $_.split("|")
if ($items[0] -ge 1 ) {Echo $items[1]}
}
But getting below error.
Method invocation failed because [Microsoft.PowerShell.Commands.MatchInfo] doesn't contain a method named 'split'.
At line:2 char:18
+ $items = $_.split <<<< ("|")
+ CategoryInfo : InvalidOperation: (split:String) [], RuntimeException
+ FullyQualifiedErrorId : MethodNotFound
Cannot index into a null array.
At line:3 char:12
+ if ($items[ <<<< 0] -lt 1 ) {Echo $items[1]}
+ CategoryInfo : InvalidOperation: (0:Int32) [], RuntimeException
+ FullyQualifiedErrorId : NullArray
Could you please help here. I am very new to the powershell scripting.
Change
$items = $_.split("|")
to:
$items = ([string]$_).split("|")
The contents of the match is returned as an array and it doesn't have a split method. Casting it to a string will give you the split method.
Update: To print the filename you have to change the script a bit since the current input for Select-String is an array so you loose the filename:
Select-String -Pattern "3-nines" -Path "*.txt" | foreach {
$items = ([string]$_).split("|")
if ([double]$items[3] -ge 1 ) {
Write-Output "FileName: $($_.Filename)"
Echo $items[3]
}
}
First of all - why would you pipe to Select-String here? You can use -Path parameter and pass *.txt directly to it.
The reason split doesn't work is because you should call it agains Line property of [Microsoft.PowerShell.Commands.MatchInfo] object. I guess what you need there is a simple Where-Object:
Select-String -Pattern 3-nines -Path *.txt |
Where-Object { [double]($_.line.Split('|')[-1]) -gt 1 } |
Select-Object Path, Line
Alternatively, you can turn content of the file into objects with Import-Csv cmdlet:
foreach ($file in Get-ChildItem -Path *.txt) {
# Existing headers are terrible - replacing them...
$3nines = Import-Csv -Path $file.FullName -Delimiter '|' -Header Percent, Read, Write, Total |
Where-Object Percent -match 3-nines
if ([double]$3nines.Total -gt 1) {
$3nines | Select-Object *, #{
Name = 'Path'
Expression = { $file.FullName }
}
}
}
Related
I have a Cypher query that shows the following output:
+----------------
| usid | count |
+----------------
| "000" | 1 |
| "000" | 0 |
| "000" | 0 |
| "001" | 1 |
| "001" | 1 |
| "001" | 0 |
| "002" | 2 |
| "002" | 2 |
| "002" | 0 |
| "003" | 4 |
| "003" | 2 |
| "003" | 2 |
| "004" | 4 |
| "004" | 4 |
| "004" | 4 |
+----------------
How can I get the below result with the condition SUM(count) <= 9.
+----------------
| usid | count |
+----------------
| "000" | 1 |
| "001" | 2 |
| "002" | 4 |
| "003" | 8 |
+----------------
Note: I have used the below query to get the 1st table data.
MATCH (us:USER)
WITH us
WHERE us.count <= 4
RETURN us.id as usid, us.count as count;
I don't know how you get your original data, so I will just use a WITH clause and assume the data is there:
// original data
WITH usid, count
// aggregate and filter
WITH usid, sum(count) as new_count
WHERE new_count <= 9
RETURN usid, new_count
Based on the updated question, the new query would look like:
MATCH (us:USER)
WHERE us.count <= 4
WITH us.id as usid, sum(us.count) as count
WHERE new_count <= 9
RETURN usid, count
˙˙˙
I am trying to parse some file and put data to the table:
File = "somehtml.file"
Data = spark.read.text(File)
df_file = Data.select(regexp_extract("col1", '(.*?)', 0).alias("somedata"), \
regexp_extract("col1", '(.*?)', 0).alias("somedata2"))
after that I have not correct result:
+--------------------+--------------------+
| somedata| somedata2|
+--------------------+--------------------+
|http://sweersdsh.ru....| |
| |helo my name lololol...|
| | |
| | |
|http://qweuiewjk.ru....| |
| |helo my name alallal...|
and I needed this one:
+--------------------+--------------------+
| somedata| somedata2|
+--------------------+--------------------+
|http://sweersdsh.ru....|helo my name lololol...|
|http://qweuiewjk.ru....|helo my name alallal...|
this out any '' , please help me
I am struggling with one code line. It is a Key generation Line for a Expert Adviser. Can someone help me figure out how I can generate key by using this line:
int key=3*(StringToInteger(StringSubstr(IntegerToString(AccountNumber()), 0, 3)))+333333;
And what is the problem?
int accountNumber = AccountNumber();
string accountNumberString = IntegerToString(accountNumber);
string accountNumberStringFirst3Digits=
StringSubstr(accountNumberString,0,3);
int accountNumberFirstThreeDigits = StringToInteger(accountNumberStringFirst3Digits);
int accountNumberFirstThreeDigitsMultiplied = 3 * accountNumberFirstThreeDigits;
int key = accountNumberFirstThreeDigitsMultiplied + 333333;
Can someone help me figure out how to generate key by this line?
Welcome, certainly, let's look on that :
int key = 3*(StringToInteger(StringSubstr(IntegerToString(AccountNumber()), 0, 3)))+333333;
Your code actually means this:
// +------------------------------------------------------------------------------- type declaration
// | +--------------------------------------------------------------------------- variable name definition
// | | +------------------------------------------------------------------------- assignment operator
// | | | +----------------------------------------------------------------------- compile-time integer constant
// | | | | +--------------------------------------------------------------------- multiply operator
// | | | | | +-------------------------------------------------- MT4 system function: StringToInteger( aString )
// | | | | | | +------------------------------------ MT4 system function: StringSubstr( aString, aPosToStartSubstrFrom, aSubstrLength )
// | | | | | | | +------------------- MT4 system function: IntegerToString( aIntNum ) | |
// | | | | | | | | +---- MT4 system function: AccountNumber() | |
// | | | | | | | | | | |
// | | | | | | | | | +------------------------------------------------------------------+ |
// | | | | | | | | | | +------------------------------------------------------------------------------+
// | | | | | | | | | | |
int key = 3 * ( StringToInteger( StringSubstr( IntegerToString( AccountNumber() ), 0, 3 ) ) )
+ 333333;
// | ||
// +------||----------------------------------------------------------------- add operator
// +|----------------------------------------------------------------- compile-time integer constant
// +----------------------------------------------------------------- literal MQL4-language syntax-terminator
The code above both defines and generates a fair integer value, so wherever your Expert Advisor code refers to a value of key, this calculated value will be used ( see also the documentation about the New-MQL4 scope-of-validity, inside which this variable remains visible ).
Can not understand why aggregateQuery always returns an empty result. Tried to test in aql, the same problem: 0 rows in set.
Indexes are all there.
aql> show indexes
+---------------+-------------+-----------+------------+-------+------------------------------+-------------+------------+-----------+
| ns | bin | indextype | set | state | indexname | path | sync_state | type |
+---------------+-------------+-----------+------------+-------+------------------------------+-------------+------------+-----------+
| "test" | "name" | "NONE" | "profiles" | "RW" | "inx_test_name" | "name" | "synced" | "STRING" |
| "test" | "age" | "NONE" | "profiles" | "RW" | "inx_test_age" | "age" | "synced" | "NUMERIC" |
aql> select * from test.profiles
+---------+-----+
| name | age |
+---------+-----+
| "Sally" | 19 |
| 20 | |
| 22 | |
| 28 | |
| "Ann" | 22 |
| "Bob" | 22 |
| "Tammy" | 22 |
| "Ricky" | 20 |
| 22 | |
| 19 | |
+---------+-----+
10 rows in set (0.026 secs)
aql> AGGREGATE mystream.avg_age() ON test.profiles WHERE age BETWEEN 20 and 29
0 rows in set (0.004 secs)
It seems that you are trying the example here.
There are two problems about the udf script. I paste the code of the lua script :
function avg_age(stream)
local function female(rec)
return rec.gender == "F"
end
local function name_age(rec)
return map{ name=rec.name, age=rec.age }
end
local function eldest(p1, p2)
if p1.age > p2.age then
return p1
else
return p2
end
end
return stream : filter(female) : map(name_age) : reduce(eldest)
end
First, there is no bin named 'gender' in your set, so you got 0 rows after aggregateQuery.
Second, this script isn't doing exactly what the function name 'avg_age' means, it just return the eldest record with name and age.
I paste my code bellow, it just replace the reduce func, and alert the map and filter func to meat the demand. You can just skip the filter process.
function avg_age(stream)
count = 0
sum = 0
local function female(rec)
return true
end
local function name_age(rec)
return rec.age
end
local function avg(p1, p2)
count = count + 1
sum = sum + p2
return sum / count
end
return stream : filter(female) : map(name_age) : reduce(avg)
end
The output looks like bellow :
AGGREGATE mystream.avg_age() ON test.avgage WHERE age BETWEEN 20 and 29
+---------+
| avg_age |
+---------+
| 22 |
+---------+
1 row in set (0.001 secs)
Can someone explain how these concept works?
I have 1 question. But I don't know have any ideas on constructing the truth table.
f(A,B,C) = AB + A’C
The answer given was ABC + ABC' + A'BC + A'B'C
And i have no idea how it get there. :-(
1. Create a column for each of the inputs, each intermediate functions, and the final function:
A B C | AB | A' | A'C | AB + A'C
--------------------------------
| | | |
| | | |
| | | |
| | | |
| | | |
| | | |
| | | |
| | | |
2. Enumerate all input possibilities, and start filling in the intermediate function values and then the final function value:
A B C | AB | A' | A'C | AB + A'C
--------------------------------
0 0 0 | 0 | 1 | 0 | 0
0 0 1 | | | |
0 1 0 | | | |
0 1 1 | | | |
1 0 0 | | | |
1 0 1 | | | |
1 1 0 | | | |
1 1 1 | | | |
3. Now, you finish the truth table.
Update per OP's edit of question:
The "answer given" can be reduced as follows using Boolean Algebra:
ABC + ABC' + A'BC + A'B'C
AB(C + C') + A'C(B + B')
AB + A'C
...which is the same as the given f(A,B,C). Not sure why ABC + ABC' + A'BC + A'B'C would be considered to be the "answer," but this does show equivalence between the two formulae.