grep -oP をwindowsでやる方法

#windowsでgrep -oP をする方法

#linuxの場合
$grep -oP "Processo.+" 1.log

$Get-Content .\1.log | Select-String  Processo.+ | ForEach-Object { $_.Matches.Value }
Processor(*)\DPC Rate
Processor(*)\% Idle Time
Processor(*)\% C1 Time
Processor(*)\% C2 Time
Processor(*)\% C3 Time
Processor(*)\C1 Transitions/sec
Processor(*)\C2 Transitions/sec
Processor(*)\C3 Transitions/sec
Processor Queue Length
Processor Time
########################################################################
#linuxの場合
$grep -oP "Processo.+" 1.log|grep -oP C. Time"

#windowsの場合
$Get-Content .\1.log | Select-String  Processo.+ | ForEach-Object { $_.Matches.Value } | Select-String "|ForEach-Object { $_.Matches.Value }
C3 Time
C2 Time
C1 Time
C3 Time
C2 Time
C1 Time
C1 Time
C2 Time
C3 Time
$
〇cmdで実行する場合
$powershell -Command "Get-Content .\1.log |Select-String  .+ | ForEach-Object { $_.Matches.Value }"
asfoadshfiou
〇引用元
xargs.bat(パスを通しておくこと)
http://www.ne.jp/asahi/hishidama/home/tech/windows/cmd/xargs.html

@echo off
rem 引数が無いとき
if "%~1"=="" (
echo usage: stdout-command ^| %0 command
echo by hishidama 2007-10-26
exit/b 1
)

set LIST=
for /f "delims=" %%i in ('findstr .*') do call :add %%i
%* %LIST%
exit/b

:add
if "%LIST%"=="" (
set LIST=%*
) else (
set LIST=%LIST% %*
)

dir /b *txt|xargs findstr java
https://github.com/asterisk9101/wincmd
type 2.log|cut /d "," /f 4
powershell<->linuxでやる場合

find:https://www.k-hitorigoto.online/entry/2020/08/06/080000
grep(-oP -P):この記事の上参照
xargs:https://www.k-hitorigoto.online/entry/2020/08/06/080000
cut:https://www.engineer-memo.net/20110122-2750
awk:https://qiita.com/ktrarai/items/9c35d7679349dd22f122
paste:https://life-is-command.com/powershell-paste/
tail:https://qiita.com/cd01/items/da9a36582372e7d0a7f6
head:
sed:https://qiita.com/cd01/items/da9a36582372e7d0a7f6
cat:cat
サブシェル$():https://yanor.net/wiki/?PowerShell/%E6%96%87%E6%B3%95/%E6%96%87%E5%AD%97%E5%88%97%E3%81%AE%E3%82%AF%E3%82%A9%E3%83%BC%E3%83%88
PS C:\Users> $a=$(ls) 
PS C:\Users> echo $a


   ディレクトリ: C:\Users


Mode                 LastWriteTime         Length Name
----                 -------------         ------ ----
d-----        2022/04/16      0:21                .baboon

この記事が気に入ったらサポートをしてみませんか?