gcue Posted May 14, 2008 Share Posted May 14, 2008 i generate a log file, is there a way i can expunge only the lines that contain a certain string of text? for instance this text file is MUCH longer than shown below - but i would like to extract the lines containing "group membership" and "home directory" to a new text file OR delete all lines except the ones containing "group membership" and "home directory" within the existing file Current context: INVEST.LAO.NA User: GXM Name: GXM Name: UT_LAO creatorsName: CN=CONRLS,OU=CRS,OU=INVEST,OU=LAO,OU=NA Given Name: Bob Group Membership: ACCESS_BROWFS15_TEAMS_DBA.CDS.. Group Membership: PC_SUPPORT.CDS.. Group Membership: Users3CRSDesktopUDrive. Group Membership: Access_Blue_Team_Share Group Membership: TS_LAO_SFO. Group Membership: LAO_TEST_LOCALBAK.GROUPS.. Home Directory: Volume Name: LAOWFS1_USERS. Path: \USER\JJBC Name Space Type: DOS Link to comment Share on other sites More sharing options...
d4rk Posted May 14, 2008 Share Posted May 14, 2008 if StringInStr(FileRead("log.txt"),"Home Directory") and StringInStr(FileRead("log.txt"),"Member Ship") then StringReplace();repalce with space for deleting Endif for Exact, look at StringSplit() [quote]Don't expect for a perfect life ... Expect a least troubles ones[/quote]Contact me : ass@kiss.toWhat I Have Done :Favorites Manager Mangage your favorite's folder, that's coolPC Waker For those who want to save stickersWebScipts Supporter For those who've just started with Web and WebScriptsTemporary Looker Simple but powerful to manage your Temporary folder, you know what you downloaded[UDF] _NumberFormat() Better performance on number display[UDF] _DirGet() What a folder contain [how many (hidden,normal,...) files], with one line of code[UDF] _IsPressEs() Just like _IsPress() but for a group of keys Link to comment Share on other sites More sharing options...
Siao Posted May 14, 2008 Share Posted May 14, 2008 StringRegExp or StringRegExpReplace. Show some effort. "be smart, drink your wine" Link to comment Share on other sites More sharing options...
weaponx Posted May 14, 2008 Share Posted May 14, 2008 $InFile = "test.txt" $OutFile = "out.txt" $Filter = "Group Membership\:.\S*" $FileContents = FileRead($InFile) $Output = StringRegExp($FileContents,$Filter,3) If IsArray($Output) Then ;FileOpen($OutFile, 2) For $X = 0 to Ubound($Output)-1 ConsoleWrite($X & ": " & $Output[$X] & @CRLF) ;FileWriteLine($OutFile, $Output[$X]) Next ;FileClose($OutFile) EndIf Link to comment Share on other sites More sharing options...
gcue Posted May 14, 2008 Author Share Posted May 14, 2008 that works great weapon! if i want to include a second filter... i added $filter2 but i cant add that to $output because you can only do one pattern at a time. and if i add $output2 then it wouldnt work either because by the time all lines except $output1 deleted, there wouldnt be an $output2 conditions left Link to comment Share on other sites More sharing options...
weaponx Posted May 14, 2008 Share Posted May 14, 2008 Maybe: $InFile = "test.txt" $OutFile = "out.txt" $Filter = "Group Membership:.\S*" $Filter &= "|Volume Name:.\S*" $FileContents = FileRead($InFile) $Output = StringRegExp($FileContents,$Filter,3) If IsArray($Output) Then ;FileOpen($OutFile, 2) For $X = 0 to Ubound($Output)-1 ConsoleWrite($X & ": " & $Output[$X] & @CRLF) ;FileWriteLine($OutFile, $Output[$X]) Next ;FileClose($OutFile) EndIf Link to comment Share on other sites More sharing options...
gcue Posted May 14, 2008 Author Share Posted May 14, 2008 works great!! thanks.. didnt know you could put multiple filters (seperating them with a pipe) thanks again! Link to comment Share on other sites More sharing options...
weaponx Posted May 14, 2008 Share Posted May 14, 2008 works great!! thanks.. didnt know you could put multiple filters (seperating them with a pipe) thanks again! You should be able to do it like this but it doesn't work: $Filter = "(Group Membership:|Volume Name:).\S*" Link to comment Share on other sites More sharing options...
Siao Posted May 14, 2008 Share Posted May 14, 2008 (edited) You should be able to do it like this but it doesn't work: $Filter = "(Group Membership:|Volume Name:).\S*"It works the way you tell it to work. You have a capturing group, so only "Group Membership:" or "Volume Name:" get captured. If you want to capture the same thing as in your first example, then the pattern should be "(?:Group Membership:|Volume Name:).\S*" Although what you have in your second example works just fine too. Actually it's probably more convenient, and maybe a tiny bit faster too. Edited May 14, 2008 by Siao "be smart, drink your wine" Link to comment Share on other sites More sharing options...
weaponx Posted May 14, 2008 Share Posted May 14, 2008 It works the way you tell it to work. You have a capturing group, so only "Group Membership:" or "Volume Name:" get captured. If you want to capture the same thing as in your first example, then the pattern should be "(?:Group Membership:|Volume Name:).\S*" I thought non-capturing meant whatever was in that group would be excluded from the output as well. Link to comment Share on other sites More sharing options...
gcue Posted May 14, 2008 Author Share Posted May 14, 2008 (edited) now the problem is - it captures the line but not the entire line: ie: Last Login Time: 12:37:21 pm 05/13/08 only the following is captured: Last Login Time: 12:37:21 (nothing after the space) i figured the * would cover any spaces too??? Edited May 14, 2008 by gcue Link to comment Share on other sites More sharing options...
Siao Posted May 14, 2008 Share Posted May 14, 2008 Open the helpfile, look at StringRegExp "Matching Characters", what does the "\S" do, and what could be used instead of it to match to the end of the line. "be smart, drink your wine" 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