TuMiM Posted January 26, 2007 Share Posted January 26, 2007 I have a text document that has a bunch of lines in it. The identifying line is different then the others because it start with an X. X-17-A-2 SRM/815409SR SRM/834596SR SRM/850182SR SRM/851908SR SRM/835251SR SRM/815403SR SRM/854826SR SRM/847991SR SRM/838633SR SRM/843808SR SRM/850655SR SRM/855544SR SRM/843810SR SRM/416064SR SRM/850653SR SRM/838020SR SRM/815405SR SRM/815407SR SRM/855545SR SRM/851906SR X-17-A-19 DLM/857472D DLM/857473D DLM/857474D DLM/859525 I need to be able to create a script that can read the file, find the lines with X at the beginning of the line and then add a <S> to the line before it. Can anyone help? Thanks Link to comment Share on other sites More sharing options...
Moderators SmOke_N Posted January 26, 2007 Moderators Share Posted January 26, 2007 (edited) _FileReadToArray() + For/Next loop + StringLeft($array[n], 1) + '<s>' & $array[n] Edit: This looks like it works as well:$sString = FileRead('text.txt') $sString = StringRegExpReplace($sString, '^X|\nX', '<s>X') Edited January 26, 2007 by SmOke_N Common sense plays a role in the basics of understanding AutoIt... If you're lacking in that, do us all a favor, and step away from the computer. Link to comment Share on other sites More sharing options...
TuMiM Posted January 30, 2007 Author Share Posted January 30, 2007 _FileReadToArray() + For/Next loop + StringLeft($array[n], 1) + '<s>' & $array[n] Edit: This looks like it works as well:$sString = FileRead('text.txt') $sString = StringRegExpReplace($sString, '^X|\nX', '<s>X') I tried the second code but it doesn't do anything to the text file. I moved the text file to the root of C and added c:\filename.txt but that didn't help. Any idea? Link to comment Share on other sites More sharing options...
Moderators SmOke_N Posted January 30, 2007 Moderators Share Posted January 30, 2007 I tried the second code but it doesn't do anything to the text file. I moved the text file to the root of C and added c:\filename.txt but that didn't help. Any idea?What did you do, just run it by itself? $hFileLocation = 'Put the exact path to your file here' $sString = FileRead($hFileLocation) $sString = StringRegExpReplace($sString, '^X|\nX', '<s>X') MsgBox(64, 'Info', $sString) Common sense plays a role in the basics of understanding AutoIt... If you're lacking in that, do us all a favor, and step away from the computer. Link to comment Share on other sites More sharing options...
TuMiM Posted February 1, 2007 Author Share Posted February 1, 2007 What did you do, just run it by itself? $hFileLocation = 'Put the exact path to your file here' $sString = FileRead($hFileLocation) $sString = StringRegExpReplace($sString, '^X|\nX', '<s>X') MsgBox(64, 'Info', $sString) Ok, I got it but that doesn't actually write it to the text file. The text file remains the way it was originally. I need the text file to be update with the changes. Would i use a filewrite? Link to comment Share on other sites More sharing options...
Shevilie Posted February 1, 2007 Share Posted February 1, 2007 That would be a good start Start here if you are new Valuater's AutoIT 1-2-3Looking for an UDF - Look hereDo you need to do it twice - Autoit Link to comment Share on other sites More sharing options...
ethnarch Posted February 1, 2007 Share Posted February 1, 2007 $hFileLocation = 'Put the exact path to your file here' $sString = FileRead($hFileLocation) $sString = StringRegExpReplace($sString, '^X|\nX', '<s>X') FileWrite("c:\filename.txt",$sString) 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