PowerShell RegEx Select Line and Parse the Fields - regex

I've a file that contains information about the programs.
What I want is to get some information about a particular prgoram.
This the structure of the file.
sometext...program.EXE;Thu, 04 May 2017 08:58:48 -0700;Wed, 27 Sep 2017 10:50:00 -0700;Wed, 04 Oct 2017 00:00:31 -0700;True;False, 17:38:05.810;30...somtext
I was to get the following detail from the above file. each field is separated with ;
p = program.exe
dt1 = Thu, 04 May 2017 08:58:48 -0700
dt2 = Wed, 27 Sep 2017 10:50:00 -0700
dt3 = Wed, 04 Oct 2017 00:00:31 -0700
d1 = True
d2 = False
Get-Content .\file.txt
So far I have \W*((?i)program.exe(?-i))\W* to match it.
But I don't know how to move forward, read all of the fields and parse it.

>> sometext...program.EXE;Thu, 04 May 2017 08:58:48 -0700;Wed, 27 Sep 2017 10:50:00 -0700;Wed, 04 Oct 2017 00:00:31 -0700;True;False, 17:38:05.810;30...somtext
>> #'|
>> Select-String '(?i)\W*(program\.exe)\W*(.*?;)(.*?;)(.*?;)(.*?;)(.*?;)'|
>> % {$_.Matches}|
>> % {$p=$_.Groups[1].Value;$dt1=$_.Groups[2].Value;$dt2=$_.Groups[3].Value;$dt3=$_.Groups[4].Value;$d1=$_.Groups[5].Value;$d2=$_.Groups[6].Value}
:\> $p
program.EXE
:\> $dt1
Thu, 04 May 2017 08:58:48 -0700;
:\> $dt2
Wed, 27 Sep 2017 10:50:00 -0700;
:\> $dt3
Wed, 04 Oct 2017 00:00:31 -0700;
:\> $d1
True;
:\> $d2
False, 17:38:05.810;
:\>
OR
IN: \> "sometext...program.EXE;Thu, 04 May 2017 08:58:48 -0700;Wed, 27 Sep 2017 10:50:00 -0700;Wed, 04 Oct 2017 00:00:31 -0700;True;False, 17:38:05.810;30..
.somtext"|
IN: >> Select-String '(?i)\W*(program\.exe)\W*(.*?;)(.*?;)(.*?;)(.*?;)(.*?;)' -OutVariable o
OUT:
sometext...program.EXE;Thu, 04 May 2017 08:58:48 -0700;Wed, 27 Sep 2017 10:50:00 -0700;Wed, 04 Oct 2017 00:00:31 -0700;True;False, 17:38:05.810;30...somtext
IN: \> $f,$p,$dt1,$dt2,$dt3,$d1,$d2=% -inputObject $o.Matches.Groups {$_.Value}
IN: \> $d2
OUT: False, 17:38:05.810;
I assigned each group to the variable required. See if this works. Apologize for any naivety, I'm not well versed with powershell.

Next try
$p,$dt1,$dt2,$dt3,$d1,$d2=#'
sometext...program.EXE;Thu, 04 May 2017 08:58:48 -0700;Wed, 27 Sep 2017 10:50:00 -0700;Wed, 04 Oct 2017 00:00:31 -0700;True;False, 17:38:05.810;30...somtext
'#|
Select-String '(program.exe)[^;]*(?:;([^;]+)){3}(?:;(true|false)){2},' -AllMatches|
ForEach-Object {$_.Matches}|
ForEach-Object {$_.Groups[1..3]}|
ForEach-Object {$_.Captures}|
Select-Object -ExpandProperty Value
$p,$dt1,$dt2,$dt3,$d1,$d2
Can this help you?
#'
sometext...program.EXE;Thu, 04 May 2017 08:58:48 -0700;Wed, 27 Sep 2017 10:50:00 -0700;Wed, 04 Oct 2017 00:00:31 -0700;True;False, 17:38:05.810;30...somtext
'#|
Select-String '([^;]+)' -AllMatches|
ForEach-Object {$_.Matches}|
ForEach-Object {$_.Groups[1].Value}

Related

reset the zoom to the initial in chart.js?

I'm new to chartjs. I applied the extension of this library to enable the zoom. At first it looks great, but as I zoom, I am unable to return to the original point where my bar chart is at the start.
Does anyone know why this happens to me or how can I fix it? thank you very much.
var ctx = document.getElementById("canvas").getContext('2d');
var myChart = new Chart(ctx, {
type: 'bar',
data: {
labels: ["08 Aug 2018 02:42 pm","09 Aug 2018 11:24 am","04 Sep 2018 01:23 pm","04 Sep 2018 01:26 pm","04 Sep 2018 01:31 pm","04 Sep 2018 01:33 pm","04 Sep 2018 01:35 pm","04 Sep 2018 01:36 pm","04 Sep 2018 01:38 pm","04 Sep 2018 01:38 pm","04 Sep 2018 01:40 pm","04 Sep 2018 01:45 pm","04 Sep 2018 01:46 pm","04 Sep 2018 01:49 pm","04 Sep 2018 01:49 pm","04 Sep 2018 01:49 pm","04 Sep 2018 01:53 pm","04 Sep 2018 02:07 pm","04 Sep 2018 02:19 pm","04 Sep 2018 02:19 pm","04 Sep 2018 02:20 pm","04 Sep 2018 02:30 pm","04 Sep 2018 02:31 pm","04 Sep 2018 02:33 pm","05 Sep 2018 09:30 am","05 Sep 2018 09:31 am","08 Aug 2018 02:42 pm","09 Aug 2018 11:24 am","04 Sep 2018 01:23 pm","04 Sep 2018 01:26 pm","04 Sep 2018 01:31 pm","04 Sep 2018 01:33 pm","04 Sep 2018 01:35 pm","04 Sep 2018 01:36 pm","04 Sep 2018 01:38 pm","04 Sep 2018 01:38 pm","04 Sep 2018 01:40 pm","04 Sep 2018 01:45 pm","04 Sep 2018 01:46 pm","04 Sep 2018 01:49 pm","04 Sep 2018 01:49 pm","04 Sep 2018 01:49 pm","04 Sep 2018 01:53 pm","04 Sep 2018 02:07 pm","04 Sep 2018 02:19 pm","04 Sep 2018 02:19 pm","04 Sep 2018 02:20 pm","04 Sep 2018 02:30 pm","04 Sep 2018 02:31 pm","04 Sep 2018 02:33 pm","05 Sep 2018 09:30 am","05 Sep 2018 09:31 am"],
datasets: [{"label":"Estatura (cm)","backgroundColor":"rgba(0, 100, 150, 0.5)","pointBorderColor":"rgba(26,179,148,1)","data":["68.00","69.00","70.00","71.00","72.00","73.00","74.00","75.00","76.00","77.00","78.00","79.00","80.00","81.00","82.00","83.00","84.00","85.00","86.00","87.00","88.00","89.00","90.00","91.00","68.00","69.00","70.00","71.00","72.00","73.00","74.00","75.00","76.00","77.00","78.00","79.00","80.00","81.00","82.00","83.00","84.00","85.00","86.00","87.00","88.00","89.00","90.00","91.00"]}]
},
options: {
legend: {
position: 'top',
},
scales: {
xAxes: [{
ticks: {
autoSkip: true,
maxRotation: 0,
minRotation: 0
}
}]
},
pan: {
enabled: false,
mode: 'xy' // is panning about the y axis neccessary for bar charts?
},
zoom: {
sensitivity:0.5, drag: false, enabled: true, mode: 'x'
}
}
});
this is my code working:
https://jsfiddle.net/ogq5uex6/2/
#yavg Please check bellow screenshot. many labels are duplicated. don't add duplicate label like this. try to add 24 hours time as my answer
I think you expected like this.
var ctx = document.getElementById("canvas").getContext('2d');
var myChart = new Chart(ctx, {
type: 'bar',
data: {
labels:
["08 Aug 2018 14:42","09 Aug 2018 11:24","04 Sep 2018 13:23","04 Sep 2018 13:26","04 Sep 2018 13:31","04 Sep 2018 13:33","04 Sep 2018 13:35","04 Sep 2018 13:36","04 Sep 2018 13:38","04 Sep 2018 13:39","04 Sep 2018 13:40","04 Sep 2018 13:45","04 Sep 2018 13:46","04 Sep 2018 13:49","04 Sep 2018 13:50","04 Sep 2018 13:51","04 Sep 2018 13:53","04 Sep 2018 14:07","04 Sep 2018 14:19","04 Sep 2018 14:20","04 Sep 2018 14:21","04 Sep 2018 14:30","04 Sep 2018 14:31","04 Sep 2018 14:33","05 Sep 2018 09:30","05 Sep 2018 09:31","08 Aug 2018 14:43","09 Aug 2018 11:25","04 Sep 2018 13:22","04 Sep 2018 13:27","04 Sep 2018 13:32","04 Sep 2018 13:34","04 Sep 2018 13:37","04 Sep 2018 13:41","04 Sep 2018 01:40","04 Sep 2018 01:41","04 Sep 2018 01:42","04 Sep 2018 01:45","04 Sep 2018 01:46","04 Sep 2018 01:49","04 Sep 2018 01:50","04 Sep 2018 01:51","04 Sep 2018 01:53","04 Sep 2018 02:07","04 Sep 2018 02:19","04 Sep 2018 02:20","04 Sep 2018 02:22","04 Sep 2018 02:36","04 Sep 2018 02:32","04 Sep 2018 02:35","05 Sep 2018 10:31","05 Sep 2018 10:32"],
datasets: [{"label":"Estatura (cm)","backgroundColor":"rgba(0, 100, 150, 0.5)","pointBorderColor":"rgba(26,179,148,1)","data":["68.00","69.00","70.00","71.00","72.00","73.00","74.00","75.00","76.00","77.00","78.00","79.00","80.00","81.00","82.00","83.00","84.00","85.00","86.00","87.00","88.00","89.00","90.00","91.00","68.00","69.00","70.00","71.00","72.00","73.00","74.00","75.00","76.00","77.00","78.00","79.00","80.00","81.00","82.00","83.00","84.00","85.00","86.00","87.00","88.00","89.00","90.00","91.00"]}]
},
options: {
legend: {
position: 'top',
},
scales: {
xAxes: [{
ticks: {
autoSkip: true,
maxRotation: 0,
minRotation: 0
}
}]
},
pan: {
enabled: false,
mode: 'xy' // is panning about the y axis neccessary for bar charts?
},
zoom: {
sensitivity:0.5, drag: false, enabled: true, mode: 'x'
}
}
});
<script src="https://cdnjs.cloudflare.com/ajax/libs/hammer.js/2.0.8/hammer.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/Chart.js/2.6.0/Chart.min.js"></script>
<script src="https://npmcdn.com/Chart.Zoom.js#0.3.0/Chart.Zoom.min.js"></script>
<canvas id="canvas" height="180"></canvas>
My Codepen Example here

RegEx: Match Within Bounded Groups

I need to match carriage-returns in blocks of text between a pre-determined tag and an indeterminate tag.
In this case, the bounding tags are:
Pre-determined: X-Gmail-Labels:
Indeterminate: (?:^[\w\-]+:) eg: Delivered-To: or ABC123:
Thanks to Wiktor Stribiżew for his answer to this thread, I have a rough idea of the solution I should pursue.
I am unsure of how to apply what I believe is needed: an uncaptured lookahead group for the bounding indeterminate tag.
Plainly stated, I'd like to delete all the carriage-returns in the text associated with the X-Gmail-Labels:. If I can match them, I can delete them!
Initial attempted regex:
(?:\bX-Gmail-Labels:|(?!^)\G)[^\r]*\K\r
Sample data:
From 1604610346950104244#xxx Fri Jun 29 12:34:35 +0000 2018
X-GM-THRID: 1604610346950104244
X-Gmail-Labels: Archived thing,Unread
Delivered-To: joe.schmoe#gmail.com
Received: by 2002:a9f:3005:0:0:0:0:0 with SMTP id h5-v6csp731836uab;
Fri, 29 Jun 2018 05:34:36 -0700 (PDT)
From 1604610346950104244#xxx Fri Jun 29 12:34:35 +0000 2018
X-GM-THRID: 1604610346950104244
X-Gmail-Labels: Also Archived
Day-of-week: Tuesday
Received: by 2002:a9f:3005:0:0:0:0:0 with SMTP id h5-v6csp731836uab;
Fri, 29 Jun 2018 05:34:36 -0700 (PDT)
From 1604610346950104244#xxx Fri Jun 29 12:34:35 +0000 2018
X-GM-THRID: 1604610346950104244
X-Gmail-Labels: Archived
thing,
Unread
Favorite-fruit: bananas
Received: by 2002:a9f:3005:0:0:0:0:0 with SMTP id h5-v6csp731836uab;
Fri, 29 Jun 2018 05:34:36 -0700 (PDT)
From 1604610346950104244#xxx Fri Jun 29 12:34:35 +0000 2018
X-GM-THRID: 1604610346950104244
X-Gmail-Labels: Archived
,Read
ABC123: DoReMe
Received: by 2002:a9f:3005:0:0:0:0:0 with SMTP id h5-v6csp731836uab;
Fri, 29 Jun 2018 05:34:36 -0700 (PDT)
From 1604610346950104244#xxx Fri Jun 29 12:34:35 +0000 2018
X-GM-THRID: 1604610346950104244
X-Gmail-Labels: Archived
thing,Unread
emais
Received: by 2002:a9f:3005:0:0:0:0:0 with SMTP id h5-v6csp731836uab;
Fri, 29 Jun 2018 05:34:36 -0700 (PDT)
(?:^[\w\-]+:)
Above regex applied to data showing indeterminate tag pattern.
(?:\bX-Gmail-Labels:\G)[^\r]*\K\r
Above regex applied to data showing un-end-bounded matches.
Thanks!
-Fitz

How to remove time date stamp from string

Hello sed/awk/bash experts,
I have thousands of certs to report on and I want to remove the time:
www.bob.com | Jul 28 19:22:38 2015 | Jul 27 19:22:38 2017
How can I (easily) remove 19:22:38 & 19:22:38 so I just have:
www.bob.com | Jul 28 2015 | Jul 27 2017
If you want to edit the file in place rather than just outputting to the screen, use a modified version of anubhava's command:
sed -E 's/[[:digit:]]{2}:[[:digit:]]{2}:[[:digit:]]{2}[[:blank:]]+//g' file > file.tmp && mv file.tmp file
It also has the added benefit of not wiping your original file should sed fail. See here.
If you're using an older version of sed you could try the following:
$ echo "www.bob.com | Jul 28 19:22:38 2015 | Jul 27 19:22:38 2017" | sed 's/\([a-zA-Z]*[ ]*[0-9]*[ ]*\)[0-9:]*\([ ]*[0-9]*\)/\1\2/g'
www.bob.com | Jul 28 2015 | Jul 27 2017
Or perhaps to just remove the time, you could instead use:
echo "www.bob.com | Jul 28 19:22:38 2015 | Jul 27 19:22:38 2017" | sed 's/[0-9][0-9]:[0-9][0-9]:[0-9][0-9]//g'
www.bob.com | Jul 28 2015 | Jul 27 2017
awk '{$5=""; $10=""; print}' file
www.bob.com | Jul 28 2015 | Jul 27 2017
Using sed:
sed -E 's/[[:digit:]]{2}:[[:digit:]]{2}:[[:digit:]]{2}[[:blank:]]+//g' file
www.bob.com | Jul 28 2015 | Jul 27 2017

How to grep lines with date formats?

I have a log file that is created from a bash script that uses $(date), so there are dates in such a format:
Fri Apr 24 22:10:39 CEST 2015
The log file looks like this:
Using SCRIPTS_ROOTDIR: /home/gillin/moses/scripts
Using multi-thread GIZA
using gzip
(1) preparing corpus # Fri Apr 24 22:10:39 CEST 2015
Executing: mkdir -p /media/2tb/ccexp/phrase-clustercat-mgiza/work.en-ru/training/corpus
(1.0) selecting factors # Fri Apr 24 22:10:39 CEST 2015
Forking...
(1.2) creating vcb file /media/2tb/ccexp/phrase-clustercat-mgiza/work.en-ru/training/corpus/en.vcb # Fri Apr 24 22:10:39 CEST 2015
(1.1) running mkcls # Fri Apr 24 22:10:39 CEST 2015
/home/gillin/moses/training-tools/mkcls -c50 -n2 -p/media/2tb/ccexp/corpus.exp/train-clean.en -V/media/2tb/ccexp/phrase-clustercat-mgiza/work.en-ru/training/corpus/en.vcb.classes opt
Executing: /home/gillin/moses/training-tools/mkcls -c50 -n2 -p/media/2tb/ccexp/corpus.exp/train-clean.en -V/media/2tb/ccexp/phrase-clustercat-mgiza/work.en-ru/training/corpus/en.vcb.classes opt
(1.1) running mkcls # Fri Apr 24 22:10:39 CEST 2015
/home/gillin/moses/training-tools/mkcls -c50 -n2 -p/media/2tb/ccexp/corpus.exp/train-clean.ru -V/media/2tb/ccexp/phrase-clustercat-mgiza/work.en-ru/training/corpus/ru.vcb.classes opt
Executing: /home/gillin/moses/training-tools/mkcls -c50 -n2 -p/media/2tb/ccexp/corpus.exp/train-clean.ru -V/media/2tb/ccexp/phrase-clustercat-mgiza/work.en-ru/training/corpus/ru.vcb.classes opt
Is there a way such that i can grep all the lines that contain the output of $(date)?
Currently I'm using this regex:
[a-z].*[1-9] [0-2][1-9]:[0-6][0-9]:[0-6][0-9] CEST 2015
And it catches line like
preparing corpus # Fri Apr 24 22:10:39 CEST 2015
But i need the full line:
(1) preparing corpus # Fri Apr 24 22:10:39 CEST 2015
And also the year and time is sort of hard coded. Is there a better regex or unix tool that can extract lines with $(date) outputs?
Try this:
unalias grep
grep --color=never '.*[a-z].*[1-9] [0-2][1-9]:[0-6][0-9]:[0-6][0-9] CEST 2015' file

SAS: Interpolate a timeseries starting with a discrete time interval

I have the following data set structure:
date time_in_hours price
Sep 03 08 9.76 98
Sep 03 08 10.43 97
Sep 03 08 10.98 96
Sep 03 08 11.48 99
Sep 04 08 2.35 98
Sep 04 08 2.58 98.45
Sep 04 08 3.45 96.3
Sep 04 08 3.89 96.25
Sep 04 08 4.18 100
Sep 05 08 12.65 101
Sep 05 08 12.96 100.25
Sep 05 08 13.25 104.35
Sep 05 08 13.78 98
My data is for the years 2008 and 2009. It contains a total of 504 trading days.
My objective is to interpolate prices at every half hour (eg 9.5 10 10.5 11 11.5...etc.) only for time interval between 9.5 and 16.
I have been struggling with the command interpolate / aggregate given that I must interpolate for a specific time interval for each calendar date. My final output must also contain the date, time, and price. Something like this:
date time_in_hours price
Sep 03 08 10 98
Sep 03 08 10.5 97
Sep 03 08 11 96
Sep 03 08 11.5 99
Sep 04 08 2.5 98
Sep 04 08 3 98.45
The code below gives you the output you have stated, but based on all comments above I am not sure it is going to solve your problem completely. Note that round(x, 0.5) takes 0.25 as the boundary - so 2.74 becomes 2.5 while 2.75 becomes 3.
data test;
infile datalines dsd;
input date :$20. time_in_hours price;
datalines;
Sep 03 08,9.76,98
Sep 03 08,10.43,97
Sep 0308,10.98,96
Sep 03 08,11.48,99
Sep 04 08,2.35,98
Sep 04 08,2.58,98.45
Sep 04 08,3.45,96.3
Sep 04 08,3.89,96.25
Sep 04 08,4.18,100
Sep 05 08,12.65,101
Sep 05 08,12.96,100.25
Sep 05 08,13.25,104.35
Sep 05 08,13.78,98
;
run;
proc print;
run;
data test2;
set test(rename = (time_in_hours = old_time_in_hours));
time_in_hours = round(old_time_in_hours, 0.5);
if (9.5 <= time_in_hours <= 16);
run;
proc print;
run;