Skip to main content

2 posts tagged with "regex"

View All Tags

[Powershell] Create folder, copy file and verify file hash, regex usage

· One min read

Method #1:

<code class="powershell">$hashPattern = "^MD5\s+(\w+)\s+";
$sourceFile = "C:\temp\6372241e-591e-4063-b15d-8aa34ae1ac63.txt";
$destFolder = "C:\app\social space\data\scp";
$destFileName = "test.txt";
$destFile = Join-Path -Path $destFolder -ChildPath $destFileName;
New-Item -ItemType Directory -Force -Path $destFolder | Out-Null;
Copy-Item $sourceFile -Destination $destFile -Force | Out-Null;
Get-FileHash $destFile -Algorithm MD5 | Out-String -Stream | Select-String -Pattern $hashPattern | % {$_.matches.Groups[1]} | % {$_.Value};

Key points: 1. Out-String, single String 2. Out-String -Stream, output each line one by one

Method #2:

<code class="powershell">$hashPattern = "^MD5\s+(\w+)\s+";
$sourceFile = "C:\temp\6372241e-591e-4063-b15d-8aa34ae1ac63.txt";
$destFolder = "C:\app\social space\data\scp";
$destFileName = "test.txt";
$destFile = Join-Path -Path $destFolder -ChildPath $destFileName;
New-Item -ItemType Directory -Force -Path $destFolder | Out-Null;
Copy-Item $sourceFile -Destination $destFile -Force | Out-Null;
certutil.exe -hashFile $destFile MD5 | Out-String | % {($_ -split '\r?\n')[1]};

Use regex to match and replace in MySql 8.0+ or MariaDB

· One min read
<code class="sql">UPDATE server_list_server
SET world_id=regexp_replace(ip,'wg(\\d+)\.glwsy\.szgla\.com;?','\\1')
WHERE ip REGEXP 'wg(\\d+)\.glwsy\.szgla\.com;?'
AND world_id!=regexp_replace(ip,'wg(\\d+)\.glwsy\.szgla\.com;?','\\1');
  • REGEXP
  • regexp_replace
  • \\1 is the placeholder for matched group
ClustrMaps