Jump to content

Read a specific character in a specific placec and write


TuMiM
 Share

Recommended Posts

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

  • Moderators

_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

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

_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

  • Moderators

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

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

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
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...