I have an interface file for example named RawData.txt which contains different regions of data which can range from a few thousand lines to nearer 100,000 lines of data.
There is a mix of lines which contain for example
01 00000000000000000000000000000198699 XYZ
which have int values other than 0 included that at times need to be replaced with
01 00000000000000000000000000000000000 XYZ
but due to the variablility of the int value between the 01 and XYZ markers a straight forward find and replace in a text editor will not work.
The part I need to manipulate is structured like below:
01 00000000000000000000000000000198699 XYZ
02 157
01 00000000000000000000000000000007749 XYZ
02 158
01 00000000000000000000000000000183279 XYZ
02 163
01 00000000000000000000000000000007749 XYZ
02 165
01 00000000000000000000000000000000000 XYZ
02 175
Ideally I am looking to put together a batch file that searches for any lines in the .txt file starting with the 01 record marker and replaces the line with:
01 00000000000000000000000000000000000 XYZ
I assume the most straight forward approach is to find any lines starting with 01 record marker and replace the whole line as the length needs to be identical after the amendments are made to the existing data.
Most examples I have found related to replacing one string with another as in the example here
and
but cannot modify to accomplish what I need from a batch file.
Any advice is appreciated.
Best Answer
This might be what you want
A batch file dealt with this surprisingly neatly!
Where
a.a
is your data fileblahblah.bat is a one line batch file
execute the batch file
That did seem to remove blank lines, there may be a way around that with batch, but another way, besides batch, is to use sed.
You could of course add
>b.b
to redirect that output to a new file, so you could dosed -r "......." a.a > b.b
i.e.sed -r "s/^01.*/01 00000000000000000000000000000000000 XYZ/" a.a > b.b