SSzretter Posted May 9, 2014 Posted May 9, 2014 (edited) Given the text below , I want to pull out all the lines that contain "Fan #" in to an array. I assume I could use a substring type command and find the position of "Fan #", chop everything up to that point, then take the Fan line. Then, repeat... I am wondering if there is a better approach? ... lots of text (snip) ... | | +- Voltage #8 : 2.144 2.144 2.144 (/lpc/it8720f/voltage/7) | | +- VBat : 3.328 3.328 3.328 (/lpc/it8720f/voltage/8) | | +- Temperature #1 : 36 36 36 (/lpc/it8720f/temperature/0 ) | | +- Temperature #2 : 30 30 30 (/lpc/it8720f/temperature/1 ) | | +- Temperature #3 : 31 31 31 (/lpc/it8720f/temperature/2 ) | | +- Fan #1 : 1054.69 1054.69 1054.69 (/lpc/it8720f/fan/0) | | +- Fan #2 : 1394.63 1394.63 1394.63 (/lpc/it8720f/fan/1) | | +- Fan Control #1 : (/lpc/it8720f/control/0) | | +- Fan Control #2 : (/lpc/it8720f/control/1) | | +- Fan Control #3 : 100 100 100 (/lpc/it8720f/control/2) | +- NVIDIA GeForce 8500 GT (/nvidiagpu/0) | +- GPU Core : 459 459 459 (/nvidiagpu/0/clock/0) | | +- Fan #1 : 1054.69 1054.69 1054.69 (/lpc/it8720f/fan/0) | | +- Fan #2 : 1394.63 1394.63 1394.63 (/lpc/it8720f/fan/1) ... lots of text (snip) ... Edited May 9, 2014 by SSzretter
jguinch Posted May 9, 2014 Posted May 9, 2014 Something like this ? #Include <Array.au3> $sContent = FileRead("file.txt") $aFan = StringRegExp($sContent, "(?m)^(.+Fan #\N+)$", 3) _ArrayDisplay($aFan) dmob 1 Reveal hidden contents Network configuration UDF, _DirGetSizeByExtension, _UninstallList Firefox ConfigurationArray multi-dimensions, Printer Management UDF
Moderators Melba23 Posted May 9, 2014 Moderators Posted May 9, 2014 (edited) SSzretter,No doubt an SRE guru will do it one line (I will have a go myself later ) but you can do it like this:#include <Array.au3> ; Simulate reading the file into an array with _FileReadToArray $sString = "| | +- Voltage #8 : 2.144 2.144 2.144 (/lpc/it8720f/voltage/7)" & @CRLF & _ "| | +- VBat : 3.328 3.328 3.328 (/lpc/it8720f/voltage/8)" & @CRLF & _ "| | +- Temperature #1 : 36 36 36 (/lpc/it8720f/temperature/0" & @CRLF & _ ")" & @CRLF & _ "| | +- Temperature #2 : 30 30 30 (/lpc/it8720f/temperature/1" & @CRLF & _ ")" & @CRLF & _ "| | +- Temperature #3 : 31 31 31 (/lpc/it8720f/temperature/2" & @CRLF & _ ")" & @CRLF & _ "| | +- Fan #1 : 1054.69 1054.69 1054.69 (/lpc/it8720f/fan/0)" & @CRLF & _ "| | +- Fan #2 : 1394.63 1394.63 1394.63 (/lpc/it8720f/fan/1)" & @CRLF & _ "| | +- Fan Control #1 : (/lpc/it8720f/control/0)" & @CRLF & _ "| | +- Fan Control #2 : (/lpc/it8720f/control/1)" & @CRLF & _ "| | +- Fan Control #3 : 100 100 100 (/lpc/it8720f/control/2)" & @CRLF & _ "|" & @CRLF & _ "+- NVIDIA GeForce 8500 GT (/nvidiagpu/0)" & @CRLF & _ "| +- GPU Core : 459 459 459 (/nvidiagpu/0/clock/0)" & @CRLF & _ "| | +- Fan #1 : 1054.69 1054.69 1054.69 (/lpc/it8720f/fan/0)" & @CRLF & _ "| | +- Fan #2 : 1394.63 1394.63 1394.63 (/lpc/it8720f/fan/1)" $aData = StringSplit($sString, @CRLF, 1) ; $STR_ENTIRESPLIT ; The file is now in an array ; Now loop through the array from the bottom up and delete unwanted lines For $i = $aData[0] To 1 Step -1 If Not StringInStr($aData[$i], "Fan #") Then _ArrayDelete($aData, $i) EndIf Next ; And this is what we get _ArrayDisplay($aData, "", Default, 8)Please ask if you have any questions. M23Edit: I see that there is now no point in my working on an SRE! Edited May 9, 2014 by Melba23 Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind Open spoiler to see my UDFs: Reveal hidden contents ArrayMultiColSort ---- Sort arrays on multiple columnsChooseFileFolder ---- Single and multiple selections from specified path treeview listingDate_Time_Convert -- Easily convert date/time formats, including the language usedExtMsgBox --------- A highly customisable replacement for MsgBoxGUIExtender -------- Extend and retract multiple sections within a GUIGUIFrame ---------- Subdivide GUIs into many adjustable framesGUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView itemsGUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeViewMarquee ----------- Scrolling tickertape GUIsNoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxesNotify ------------- Small notifications on the edge of the displayScrollbars ----------Automatically sized scrollbars with a single commandStringSize ---------- Automatically size controls to fit textToast -------------- Small GUIs which pop out of the notification area
jguinch Posted May 9, 2014 Posted May 9, 2014 @Melba : in your final array, you should delete the first row (the number of rows returned by StringSplit), which is useless Reveal hidden contents Network configuration UDF, _DirGetSizeByExtension, _UninstallList Firefox ConfigurationArray multi-dimensions, Printer Management UDF
Moderators Melba23 Posted May 9, 2014 Moderators Posted May 9, 2014 jguinch,As my old maths teacher used to say: "An example for the student to complete". M23 Danyfirex 1 Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind Open spoiler to see my UDFs: Reveal hidden contents ArrayMultiColSort ---- Sort arrays on multiple columnsChooseFileFolder ---- Single and multiple selections from specified path treeview listingDate_Time_Convert -- Easily convert date/time formats, including the language usedExtMsgBox --------- A highly customisable replacement for MsgBoxGUIExtender -------- Extend and retract multiple sections within a GUIGUIFrame ---------- Subdivide GUIs into many adjustable framesGUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView itemsGUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeViewMarquee ----------- Scrolling tickertape GUIsNoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxesNotify ------------- Small notifications on the edge of the displayScrollbars ----------Automatically sized scrollbars with a single commandStringSize ---------- Automatically size controls to fit textToast -------------- Small GUIs which pop out of the notification area
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now