Sign in to follow this  
Followers 0
TuMiM

Read a specific character in a specific placec and write

7 posts in this topic

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

Share this post


Link to post
Share on other sites



#2 ·  Posted (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 by SmOke_N

[center]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.[/center]

Share this post


Link to post
Share on other sites

_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?

Share this post


Link to post
Share on other sites

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)

[center]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.[/center]

Share this post


Link to post
Share on other sites

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?

Share this post


Link to post
Share on other sites

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

Share this post


Link to post
Share on other sites

$hFileLocation = 'Put the exact path to your file here'

$sString = FileRead($hFileLocation)

$sString = StringRegExpReplace($sString, '^X|\nX', '<s>X')

FileWrite("c:\filename.txt",$sString)

Share this post


Link to post
Share on other sites

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 account

Sign in

Already have an account? Sign in here.


Sign In Now
Sign in to follow this  
Followers 0