This might be what you want
A batch file dealt with this surprisingly neatly!
Where a.a
is your data file
blahblah.bat is a one line batch file
C:\Users\harvey>type blahblah.bat
@for /f "tokens=1,2 delims= " %%f in (a.a) do @IF "%%f"=="01" (echo 01 00000000000000000000000000000000000 XYZ) ELSE IF NOT "%%f"=="01" ECHO %%f %%g
C:\Users\harvey>
execute the batch file
C:\Users\harvey>blahblah
01 00000000000000000000000000000000000 XYZ
02 157
01 00000000000000000000000000000000000 XYZ
02 158
01 00000000000000000000000000000000000 XYZ
02 163
01 00000000000000000000000000000000000 XYZ
02 165
01 00000000000000000000000000000000000 XYZ
02 175
C:\Users\harvey>
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.
C:\Users\harvey>sed -r "s/^01.*/01 00000000000000000000000000000000000 XYZ/" a.a
01 00000000000000000000000000000000000 XYZ
02 157
01 00000000000000000000000000000000000 XYZ
02 158
01 00000000000000000000000000000000000 XYZ
02 163
01 00000000000000000000000000000000000 XYZ
02 165
01 00000000000000000000000000000000000 XYZ
02 175
You could of course add >b.b
to redirect that output to a new file, so you could do sed -r "......." a.a > b.b
i.e. sed -r "s/^01.*/01 00000000000000000000000000000000000 XYZ/" a.a > b.b
The width of all the symbols depends heavily on the font used. There is no easy way to measure pixel width of a string, but sometimes you don't need it.
Windows command line by default uses Lucida Console, a monospace font, which makes things easy. Example would be:
@echo off
setLocal EnableDelayedExpansion
set "STR=Boom^!"
set "SIZE=50"
set "LEN=0"
:strLen_Loop
if not "!!STR:~%LEN%!!"=="" set /A "LEN+=1" & goto :strLen_Loop
set "stars=****************************************************************************************************"
set "spaces= "
call echo %%stars:~0,%SIZE%%%
set /a "pref_len=%SIZE%-%LEN%-2"
set /a "pref_len/=2"
set /a "suf_len=%SIZE%-%LEN%-2-%pref_len%"
call echo *%%spaces:~0,%pref_len%%%%%STR%%%%spaces:~0,%suf_len%%%*
call echo %%stars:~0,%SIZE%%%
endLocal
SIZE here is the length of the block you want to output, make sure it's big enough to fit all the possible lines inside it.
I'll remind, that this will output a pretty block in monospace fonts only.
EDIT: Fixed the LEN initialization.
Best Answer
I'm looking to extract the text before an equal sign in a string of text
Use the following batch file (test.cmd):
Example output:
Further Reading