dplaut Posted October 2, 2018 Share Posted October 2, 2018 I have 1 file. There is one blank line at a random point in the file. I need to split this file into two different files. File #1 is all text above the blank line. File #2 is all text below the blank line. Any help appreciated. Link to comment Share on other sites More sharing options...
Moderators Melba23 Posted October 2, 2018 Moderators Share Posted October 2, 2018 dplaut, Read the file into an array - look for the blank line - write the new files from the array using that line index as the stop/start point for the elements written. M23 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: Spoiler 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 Link to comment Share on other sites More sharing options...
dplaut Posted October 2, 2018 Author Share Posted October 2, 2018 Thanks, I'll try that Link to comment Share on other sites More sharing options...
pixelsearch Posted October 2, 2018 Share Posted October 2, 2018 Now image the file you want to split is... the following script, which contains a single blank line in it. Another solution could be to read your file into a single string (you'll have to add some error checking in the script) Uncomment the 2 FileWrite() lines if you want to the 2 resulting files to be written in your script directory #include <MsgBoxConstants.au3> Example() Func Example() $sContent = FileRead(@ScriptFullPath) $iEmpty_line = StringInStr($sContent, @CRLF & @CRLF) ; 4 characters = 1 empty line $sContent_left = StringLeft($sContent, $iEmpty_line + 1) ; +1 includes 1st @CRLF $sContent_right = StringMid($sContent, $iEmpty_line + 4) ; +4 bypass @CRLF & @CRLF MsgBox($MB_SYSTEMMODAL, "Before empty line", $sContent_left) MsgBox($MB_SYSTEMMODAL, "After empty line", $sContent_right) ; FileWrite(@ScriptDir & "\todelete1.txt", $sContent_left) ; FileWrite(@ScriptDir & "\todelete2.txt", $sContent_right) EndFunc ;==>Example Link to comment Share on other sites More sharing options...
mikell Posted October 3, 2018 Share Posted October 3, 2018 If the blank line contains no white spaces AND the newlines are all @crlf, then you can use StringSplit $s = StringSplit($txt, @crlf & @crlf, 3) Else you can use a regex $s = StringRegExp($txt, '(?s)(.*?\R)\h*\R(.*)', 3) In both cases the 2 parts are in $s[0] and $s[1] Link to comment Share on other sites More sharing options...
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