Merge texts from discontinuous areas - regex

I need to delete the content in the red rectangle in picture 1, and then generate a new text file.
Also, replace AIDA64 Engineer with AIDA64 Ultimate
Because the reserved fields are divided into different areas, for example: Motherboard:, it seems to be somewhat difficult
In the following post, some related issues have been resolved.
Get strings for some specific region
--------[ AIDA64 Engineer ]------------------------------------------------------------
version AIDA64 Engineer v6.00.5100/cn
--------[ System verview ]-------------------------------------------------------------
Motherboard:
Processor name Mobile DualCore Intel
DMI:
DMI BIOS Vendor Phoenix Technologies
--------[ DMI ]------------------------------------------------------------------------
[ BIOS ]
BIOS Attributes:
Vendor Phoenix Technologies Ltd.
[ Motherboard ]
Motherboard:
manufacturer Intel Corp.
Motherboard manufacturer:
company name Intel Corporation
--------[ Overclocking ]---------------------------------------------------------------
Motherboard:
Motherboard ID <DMI>
BIOS Attributes:
System BIOS date 12/24/2012
--------[ PCI/PnP Network ]------------------------------------------------------------
Atheros AR5009 802.11a/g/n Wireless PCI
Broadcom NetLink BCM57785 PCI-E PCI

Since the strings to remove seem to have nothing in common, this long regex replace might help:
$re = '\s+(DMI:\s+DMI BIOS Vendor|Motherboard manufacturer:\s+company name|BIOS Attributes:\s+System BIOS date)[^-]+'
$nlnl = ([Environment]::NewLine * 2) # replace with two newlines
(Get-Content -Path 'PATH TO THE FILE' -Raw) -replace $re, $nlnl -replace 'AIDA64 Engineer', 'AIDA64 Ultimate'
Result:
--------[ AIDA64 Ultimate ]------------------------------------------------------------
version AIDA64 Ultimate v6.00.5100/cn
--------[ System verview ]-------------------------------------------------------------
Motherboard:
Processor name Mobile DualCore Intel
--------[ DMI ]------------------------------------------------------------------------
[ BIOS ]
BIOS Attributes:
Vendor Phoenix Technologies Ltd.
[ Motherboard ]
Motherboard:
manufacturer Intel Corp.
--------[ Overclocking ]---------------------------------------------------------------
Motherboard:
Motherboard ID <DMI>
--------[ PCI/PnP Network ]------------------------------------------------------------
Atheros AR5009 802.11a/g/n Wireless PCI
Broadcom NetLink BCM57785 PCI-E PCI
Edit
If you only want to replace AIDA64 Engineer in the header and not also in the text later on, change this part:
-replace 'AIDA64 Engineer', 'AIDA64 Ultimate'
into
-replace '\[ AIDA64 Engineer \]', '[ AIDA64 Ultimate ]'

Related

Removing all extra white spaces apart from New Line - Regex in Power Automate Desktop

Having difficulty with Power Automate Desktop, trying to convert this:
OS Name : Microsoft Windows 10 Pro
System Name : DESKTOP-VHCTR2M
Processor : Intel(R) Core(TM) i7 CPU 920 # 2.67GHz, 2668 Mhz, 4 Core(s), 8 Logical Processor(s)
BIOS Version/Date : American Megatrends Inc. 0504, 19/05/2009
BaseBoard Manufacturer : ASUSTeK Computer INC.
BaseBoard Product : P6T DELUXE V2
Platform Role : Desktop
Secure Boot State : Unsupported
Installed Physical Memory (RAM) : 32.0 GB
Remove all extra white spaces but keep the new line so the outcome would look like this:
OS Name : Microsoft Windows 10 Pro
System Name : DESKTOP-VHCTR2M
Processor : Intel(R) Core(TM) i7 CPU 920 # 2.67GHz, 2668 Mhz, 4 Core(s), 8 Logical Processor(s)
BIOS Version/Date : American Megatrends Inc. 0504, 19/05/2009
BaseBoard Manufacturer : ASUSTeK Computer INC.
BaseBoard Product : P6T DELUXE V2
Platform Role : Desktop
Secure Boot State : Unsupported
Installed Physical Memory (RAM) : 32.0 GB
So all text has 1 white space and not random spaces.
Any help will be appreciated.
[^\S\r\n]{2,}
This seems to work.

Regex to match words but not numbers with certain characters

I'm trying to match company names and ignore measurements/quantities. But I'm having a bit of trouble.
Example data:
8G Kingston Single DDR3-1600 CL11 Desktop RAM (KVR16N11/8)
8 Outlet Belkin Surge Protector With 2 Meter Cord
0.5M Yellow CAT6 Network Cable
100" Intact 16x -R DVD
15.6" Topload Notebook (Black)
120mm Aluminum Filter Silver
8P TP-Link 10/100 Desktop Switch
8Ware 0.5M CAT5E Network Cable
Acer Aspire Alpha 12" QHD IPS Display Intel Core i7 Touch Laptop
ACER Aspire E5 15.6" HD Intel Core i5 Laptop
Asus SDRW-08D2S-U Slim External USB 2.0 DVD Read/Writer - Black
I was hoping to match the company names but ignore the gigabytes (G) single digits, 100", 15.6" tokens etc.
So ideally it'd match:
Kingston Single DDR3-1600 CL11 Desktop RAM (KVR16N11/8)
Outlet Belkin Surge Protector With 2 Meter Cord
Yellow CAT6 Network Cable
Intact 16x -R DVD
Topload Notebook (Black)
Aluminum Filter Silver
TP-Link 10/100 Desktop Switch
8Ware 0.5M CAT5E Network Cable
Acer Aspire Alpha 12" QHD IPS Display Intel Core i7 Touch Laptop
ACER Aspire E5 15.6" HD Intel Core i5 Laptop
Asus SDRW-08D2S-U Slim External USB 2.0 DVD Read/Writer - Black
The expression I tweaked with is below, but I'm matching mm (the 120mm line) because I want the 8Ware matching.
Based upon the data you have provided, I have come up with a regex which you can use. Here is the sample code that you can run and see it prints your desired results.
public static void main(String[] args) {
List<String> dataList = new ArrayList<String>();
dataList.add("8G Kingston Single DDR3-1600 CL11 Desktop RAM (KVR16N11/8)");
dataList.add("8 Outlet Belkin Surge Protector With 2 Meter Cord");
dataList.add("0.5M Yellow CAT6 Network Cable");
dataList.add("100\" Intact 16x -R DVD");
dataList.add("15.6\" Topload Notebook (Black)");
dataList.add("120mm Aluminum Filter Silver");
dataList.add("8P TP-Link 10/100 Desktop Switch");
dataList.add("8Ware 0.5M CAT5E Network Cable");
dataList.add("Acer Aspire Alpha 12\" QHD IPS Display Intel Core i7 Touch Laptop");
dataList.add("ACER Aspire E5 15.6\" HD Intel Core i5 Laptop");
dataList.add("Asus SDRW-08D2S-U Slim External USB 2.0 DVD Read/Writer - Black");
System.out.println("Before:");
for (String s : dataList) {
System.out.println(s);
}
System.out.println();
System.out.println("After:");
for (String s : dataList) {
System.out.println(s.replaceAll("(^[0-9.]+[a-zA-Z\"]{0,2}\\s+)(.*)", "$2"));
}
}
Following is the output of this program upon running which is exactly what you wanted.
Before:
8G Kingston Single DDR3-1600 CL11 Desktop RAM (KVR16N11/8)
8 Outlet Belkin Surge Protector With 2 Meter Cord
0.5M Yellow CAT6 Network Cable
100" Intact 16x -R DVD
15.6" Topload Notebook (Black)
120mm Aluminum Filter Silver
8P TP-Link 10/100 Desktop Switch
8Ware 0.5M CAT5E Network Cable
Acer Aspire Alpha 12" QHD IPS Display Intel Core i7 Touch Laptop
ACER Aspire E5 15.6" HD Intel Core i5 Laptop
Asus SDRW-08D2S-U Slim External USB 2.0 DVD Read/Writer - Black
After:
Kingston Single DDR3-1600 CL11 Desktop RAM (KVR16N11/8)
Outlet Belkin Surge Protector With 2 Meter Cord
Yellow CAT6 Network Cable
Intact 16x -R DVD
Topload Notebook (Black)
Aluminum Filter Silver
TP-Link 10/100 Desktop Switch
8Ware 0.5M CAT5E Network Cable
Acer Aspire Alpha 12" QHD IPS Display Intel Core i7 Touch Laptop
ACER Aspire E5 15.6" HD Intel Core i5 Laptop
Asus SDRW-08D2S-U Slim External USB 2.0 DVD Read/Writer - Black
Like I said above, I have already given you a base regex and you may have to tweak it based upon your actual data if case you have more, else you are good already.
EDIT1:
Ok, as requested in comments, editing the answer to include the explanation of the regex.
(^[0-9.]+[a-zA-Z\"]{0,2}\s+)(.*)
The regex has two parts. First part (^[0-9.]+[a-zA-Z\"]{0,2}\s+) tries to match the measurements/quantities data. And second part just tries to match the remaining data which is supposedly the rest of the line. Elaborating only first part as second part (.*) is pretty trivial.
(^[0-9.]+[a-zA-Z\"]{0,2}\s+)
^ --> is for matching the start of data as measurement data is in the beginning of the line.
[0-9.]+ --> Matches the numbers one or more in the measurements/quantities data which can include a dot character.
[a-zA-Z\"]{0,2} --> This matches the units of data like G,M,mm," which according to given data can have length 0 to 2. E.g. "8 Outlet..." line does not have any units hence I had to use {0,2} else could have used {1,2}. And to avoid matching "8Ware ..." as measurement data, which you didn't want to match, I had to restrict the upper limit to 2.
\s+ is to just eat up one or more spaces present after measurement data.
So whole regex is matched and then replaced by $2, meaning only data captured by second part of regex (.*)
Hope that clarifies. Let me know in case you need explanation on any part further.

computer systems using the AMD chipset and RAID how to get the HDD serial number?

I took the HDD serial number but it did not result in systems using AMD chipset. In the case of computer systems using RAID then how to get HDD serial number?
SelectQuery sq = new SelectQuery("SELECT Tag, SerialNumber FROM Win32_PhysicalMedia");
ManagementObjectSearcher searcher = new ManagementObjectSearcher(sq); foreach (var i2 in searcher.Get()) { string Tag = i2["Tag"].ToString();
if (Tag != "\\.\PHYSICALDRIVE0")
continue;
string serial = i2["SerialNumber"].ToString();
File.WriteAllText("C:\Caditsys\Serial.txt", serial + Environment.NewLine + DateTime.Now.ToString("dd/MM/yyyy"));
Sometimes its easiest to leverage SmartMonTools. I'm assuming you are using software raid. SmartMonTools will usually tell you the serial number of anything plugged into the motherboard.
smartctl --scan
smartctl -i $yourdevice
If your disks are behind a hardware RAID controller, it gets trickier, but you can still use smartctl with the -d flag specific to your hardware device.

strange slowing down of C++ allocs

Could someone please tell me why following things could happen:
I have 2 computers:
my working comp
Server
I maintain C++ program (msvc 2005 c++ compiled) that works too slow only on server,
but not on my comp.
I conducted measurements (GetThreadTimes and so on)
and could definitely say that the narrow place - its memory allocation
(new/malloc). And it happens only on server!
I could claim that it happens due to memory fragmentation because of
1st time server instance of program works fine, its start loosing time
on allocs only after data reload again into memory (1-1.5 million allocs/frees).
I wouldnt be so surprised if I see the same behaviour due to memory
fragmentation on both computers (my comp and server)
but what I see is:
1). on my comp allocations take ~5% of time (not exact but someting like that)
2). on the server these allocs takes ~75% of time
how this could happen? What could slow down C++ allocations on Server computer,
meanwhile its OK for my workstation. Where could be difference?
Probably its something connected with OS-level memory management functions?
because the C++ level manager the same in both cases.
Here is both configurations:
1). My computer (where allocs take ~5%):
OS Name: Microsoft Windows 7 Enterprise
OS Version: 6.1.7600 N/A Build 7600
OS Manufacturer: Microsoft Corporation
OS Configuration: Member Workstation
OS Build Type: Multiprocessor Free
Registered Owner: Windows User
Original Install Date: 16/09/2011, 19:37:43
System Boot Time: 05/04/2013, 11:58:11
System Model: 7304A58
System Type: x64-based PC
Processor(s): 1 Processor(s) Installed.
[01]: Intel64 Family 6 Model 23 Stepping 10 GenuineIntel ~2642 Mhz
Windows Directory: C:\Windows
System Directory: C:\Windows\system32
Boot Device: \Device\HarddiskVolume2
System Locale: ru;Russian
Input Locale: en-us;English (United States)
Total Physical Memory: 4,061 MB
Available Physical Memory: 872 MB
Virtual Memory: Max Size: 8,121 MB
Virtual Memory: Available: 4,579 MB
Virtual Memory: In Use: 3,542 MB
Page File Location(s): C:\pagefile.sys
2). Server (where allocs take ~75%):
OS Name: Microsoft(R) Windows(R) Server 2003, Enterprise Edition
OS Version: 5.2.3790 Service Pack 2 Build 3790
OS Manufacturer: Microsoft Corporation
OS Configuration: Member Server
OS Build Type: Multiprocessor Free
Original Install Date: 11/12/2008, 01:22:57
System Up Time: 1 Days, 8 Hours, 35 Minutes, 52 Seconds
System Manufacturer: HP
System Model: ProLiant BL685c G5
System Type: X86-based PC
Processor(s): 4 Processor(s) Installed.
[01]: x86 Family 16 Model 2 Stepping 3 AuthenticAMD ~2210 Mhz
[02]: x86 Family 16 Model 2 Stepping 3 AuthenticAMD ~2210 Mhz
[03]: x86 Family 16 Model 2 Stepping 3 AuthenticAMD ~2210 Mhz
[04]: x86 Family 16 Model 2 Stepping 3 AuthenticAMD ~2210 Mhz
Windows Directory: C:\WINNT
System Directory: C:\WINNT\system32
Boot Device: \Device\HarddiskVolume1
Total Physical Memory: 65,534 MB
Available Physical Memory: 61,284 MB
Page File: Max Size: 97,696 MB
Page File: Available: 93,445 MB
Page File: In Use: 4,251 MB
Page File Location(s): C:\pagefile.sys
D:\pagefile1\pagefile.sys
D:\pagefile2\pagefile.sys
D:\pagefile3\pagefile.sys
D:\pagefile4\pagefile.sys
D:\pagefile5\pagefile.sys
D:\pagefile6\pagefile.sys
D:\pagefile7\pagefile.sys
Will be grateful for clarifying this issue.
The problem could be that the memory functions use only one mutex to lock the memory for allocation and freeing.

WMI Win32_BaseBoard SerialNumber

I used Win32_BaseBoard SerialNumber property to obtain the motherboard serial number and it work most of the time, but sometimes in some computers I get SerialNumber = "Base Board Serial Number" as a result.
Is there a programmatic way to obtain this serial number in a more efficient way or it is simply a manufacturer problem? I have heard that all motherboards come with a serial number with no exception. Is this true?
Whether the Serial Number returned by various WMI queries will be correct or not will depend on the manufacturer of the device. See the answer to this stackoverflow question, Motherboard ID - WMI C++ Reliable? which contains a couple of examples showing that your results can vary.
Some of the variables are whether the equipment is OEM or not and whether the equipment was purchased from a manufacturer who sells to the end customer such as Dell or a manufacturer who sells equipment to resellers who then configure the equipment or if the equipment was assembled from purchased parts.
Those results are processing the properties retrieved by several different WMI queries.
L"SELECT * FROM Win32_SystemEnclosure",
L"SELECT * FROM Win32_BaseBoard",
L"SELECT * FROM Win32_BIOS",
L"SELECT * FROM Win32_ComputerSystem",
L"SELECT * FROM Win32_ComputerSystemProduct",
L"SELECT * FROM Win32_MotherboardDevice",
For instance here is from a point of sale terminal that shows missing serial number information. The intent seems to be that the reseller or dealer or other vendor will provide their own serial number along with other information to basically relabel the terminal.
Connected to ROOT\CIMV2 WMI namespace
Query for SELECT * FROM Win32_SystemEnclosure
SMBIOS SerialNumber: None
SMBIOS Name: System Enclosure
SMBIOS SMBIOSAssetTag: None
SMBIOS Manufacturer: To Be Filled By O.E.M.
Query for SELECT * FROM Win32_BaseBoard
SMBIOS SerialNumber: None
SMBIOS Product: EIN70-SAM
SMBIOS Name: Base Board
SMBIOS Manufacturer: INTEL Corporation
Query for SELECT * FROM Win32_BIOS
SMBIOS SerialNumber: None
SMBIOS Name: BIOS Date: 10/15/13 20:06:15 Ver: 04.06.05
SMBIOS Manufacturer: American Megatrends Inc.
Query for SELECT * FROM Win32_ComputerSystem
SMBIOS Name: GENPOSA-1
SMBIOS Manufacturer: To be filled by O.E.M.
Query for SELECT * FROM Win32_ComputerSystemProduct
SMBIOS Name: EIN70-SAM
SMBIOS IdentifyingNumber: None
SMBIOS UUID: 03000200-0400-0500-0006-000700080009
It is possible that the information is not exposed to WMI. You can confirm this easily using wbemtest.exe (or WMI CIM Studio if you have it installed). On my current computer Win32_BaseBoard.SerialNumber is not null but an empty string. If this is the case you will need to find another way to get this information.
I had a similar problem. You can try out this query and see if it works for you. select UUID from Win32_ComputerSystemProduct