batch replace text in a file with text from a CSV

I had this question after viewing batch findtext match 2 criteria.

related to this, i have no problem working with the output i need to clean up my text file now
I have 3 csv files in the folder Z:\OP\CSV

one is SUBDATA.CSV
AccountID,AcctLineCode,AcctNum,AcctNumArea,RadioAcctLineCode,RadioAcctNum,Name,Address,City,State,Zip,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,
1,DR1,14,,,,MALCOM X,12640 SOUTH HWY 63,MISSISSIPPI,TX,88888,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,
2,DC1,2346,,,,DC 9-17-2015 FAIR PLAY GRADE SCHOOL,301 NORTH WALNUT,POTATO,MO,99988,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,
4,DSA,3382,,,,"WUBBLU, DON & TOM",17699 MARBEL ROAD 519,WITCHY,WC,78899,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,

Open in new window


My output file looks like
02/01/18 10:11:55 ( 0) Fire Alarm      3          DS-5382 XXXXXXXXXX 
02/01/18 10:12:38 ( 0) Fire Alarm      2          DS-3682 XXXXXXXXXX
02/01/18 10:12:38 ( 0) Fire Alarm      4          DS-3234 XXXXXXXXXX 
02/01/18 10:14:16 ( 0) Panic Alarm     2          DSA-3382 WUBBLU, DO

Open in new window

is there a way to remove the end text and replace it with the text from the 8th - 12th valeu in the csv

So it would look more like this
02/01/18 10:11:55 ( 0) Fire Alarm      3          DS-5382 XXXXXXXXXXXXX 56789 REAL STREET NAME NOTOWN QL 12345 
02/01/18 10:12:38 ( 0) Fire Alarm      2          DS-3682 XXXXXXXXXXXXXXXXXXXXXX 11135 ANOTHER STREET NAME SOMETOWN HI 12345
02/01/18 10:12:38 ( 0) Fire Alarm      4          DS-3234 XXXXXXXXXXXXX 1 REAL STREET NAME ATOWN CA 12345 
02/01/18 10:14:16 ( 0) Panic Alarm     2          DSA-3382 WUBBLU, DON & TOM 17699 MARBEL ROAD 519 WITCHY WC 78899

Open in new window

LVL 1
csePixelatedAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Bill PrewCommented:
Honestly, I don't fully understand the details of your question (like what is the "key" from the output file that is used to match to a record in the SUBDATA file?  But even given that, assuming that exists, this is starting to feel less like a BAT script task and more like an Excel , VBscript or Powershell job.

Working with CSV files is weak at best in BAT, and treating them as "tables" where you want to lookup data in them during the script is pretty hard, and slow.

Also, know what to strip off the end of the output file (XXXXXXXXXXXXXXXXXXX) could be a challenge if it contains spaces, etc.  How would the part to keep and the part to remove be clearly identified.

Just my initial thoughts...


»bp
0
csePixelatedAuthor Commented:
i can definitely see your confusion i screwed up the data. the csv is from a sql table
unfortunately my output file would not have a key, although it would have  data that is unique to it the 2nd and 3rd values are equal to the values starting at the 51st character in the output file.

It would be everything after the 57th or the 58th character , the 51st character is always the 1st character in the information i am looking for
0
Ben Personick (Previously QCubed)Lead Network EngineerCommented:
So... your data has a lot of NULL values, and CMD loops don't like NULL values.

IE  "someting,,,,something" = "someting,NULL,NULL,NULL,something"

to do this we could do something as follows

@(
  SETLOCAL ENABLEDELAYEDEXPANSION
  SET "_Null=@@@@@"
  SET "_CorrelationFile=C:\Path\To\SUBDATA.CSV"
  SET "_eLvl=0"
)

CALL :Main %*

(
  ENDLOCAL
  EXIT /B %eLvl%
)
:Main

  REM Ceate variables which hold the school addresses
  CALL :LoadSubData
  
  REM Correlate the address recieved with the variables held in memory and update the info.
  CALL :CorrelateData %*
  ECHO The Resulting string is %_Result%

GOTO :EOF

:CorrelateData
  ECHO.  Correlating "%~7" to the Schools List
  FOR /F "Tokens=2 Delims==" %%A IN ('SET ^|FIND /I "_School_%~7"') DO (
    SET "_Result=%1 %2 %3 %4 %5 % 6 %7 %%A"
    GOTO :EOF
  )
GOTO :EOF

:LoadSubData
  FOR %%A IN (%_CorrelationFile%) DO (
    SET "_ATmp=%%A"
    FOR /F "Tokens=1,2,8,9,10,11,12 delims=," %a IN ('ECHO.!%_ATmp:,,=,@@@@@,!') DO (
      SET "_School_%%~a-%%~b=%%~c %%~d %%~e %%~f %%~g
      CALL SET "_School_%%~a-%%~b=!_School_%%%%~a-%%%%~b:@@@@@=!
    )
  )
GOTO :EOF

Open in new window


Example Input Expected to be passed as an argument:
02/01/18 10:14:16 ( 0) Panic Alarm     2          DS-3382 WUBBLU, DO 

Open in new window


Example Output:
02/01/18 10:14:16 ( 0) Panic Alarm 2 DS-3382 WUBBLU, DON & TOM 17699 MARBEL ROAD 519 WITCHY WC 78899

Open in new window


Now, this only finds one correlation which is passed from the command prompt to the script, this is a lot to do to find each and every correlation if you need to pass them.

 There are two alternatives.  One is you loop through all of the values you want to correlate calling just the correlate function after loading them into memory (this is the best option if you have a lot of things you want to correlate each time you run this, and don't run it often.)

Or modify this to find the best line first from the original CSV file, using a find, and then only load that line (best option if you want to run this one at a time occasionally.

Edit, I am assuming ALL data after the school needs to be replaced with the address info from the SubData.csv table, as In the example I was looking at it appeared to be true.  However, I see from your follow-up message that you want to retain only certain data.

  When you say you want to keep the 51st character to the 57th/58th:

   first off, is there a way of knowing whether the 57th or 58th is correct?
   second off, that when you say 51st character, so are you starting from the beginning of the line, or are you saying after the school's ID?  I am using the school's IDto correlate info, as there would be no other way to be certain of what goes where, is the a set number of characters after the schools ID at which your data you want to keep starts?.
0
Cloud Class® Course: Microsoft Exchange Server

The MCTS: Microsoft Exchange Server 2010 certification validates your skills in supporting the maintenance and administration of the Exchange servers in an enterprise environment. Learn everything you need to know with this course.

csePixelatedAuthor Commented:
Ben, starting from the 51st character the next space is where i would need it cut off.
or if it were DSA then the cutoff would be after 58 else it would be after 57

02/01/18 10:11:55 ( 0) Fire Alarm      3          DS-5382 XXXXXXXXXX 
02/01/18 10:12:38 ( 0) Fire Alarm      2          DS-3682 XXXXXXXXXX
02/01/18 10:12:38 ( 0) Fire Alarm      4          DS-3234 XXXXXXXXXX 
02/01/18 10:14:16 ( 0) Panic Alarm     2          DSA-3382 WUBBLU, DO

Open in new window


Bill i am not opposed to a powershell script however i have not even dabbled in that, if i use PS could i instead of referencing a csv could i reference the database directly? no matter what im limited by the output file, as it is a captured file from an LPT port (my file is a simulation of an old tractor fed printer)
i need to update this rather regularly, i was planning on setting up a loop in the batch file to wait 30 sec then do it all again. as someone will be constantly monitoring the output.
0
Bill PrewCommented:
How many records would typically be in each file?  Can you provide a more real / robust sample of each for testing?


»bp
0
Ben Personick (Previously QCubed)Lead Network EngineerCommented:
So I can codify as:  IF School name starts "DS-" then 57th Character" If the School name is DSA then "58th Character"

However, I just looked at your examples.
02/01/18 10:12:38 ( 0) Fire Alarm      4          DS-3234 XXXXXXXXXX 
02/01/18 10:14:16 ( 0) Panic Alarm     2          DSA-3382 WUBBLU, DO

Open in new window


"02/01/18 10:12:38 ( 0) Fire Alarm      4          DS-3234" == 57 Characters
"02/01/18 10:14:16 ( 0) Panic Alarm     2          DSA-3382" == 58 Characters

Do you need any of the characters after these values at all, or can I just match and put the address?
0
Ben Personick (Previously QCubed)Lead Network EngineerCommented:
@OP, If you are trying to match the school names, I am already doing that.

Are you trying to to this:

MM/DD/YY HH:MM:SS ( X) Fire Alarm      Y          DC1-2346 [SOME OTHER STUFF TO DELETE]

Open in new window


becomes
MM/DD/YY HH:MM:SS ( X) Fire Alarm      Y          DC1-2346 DC 9-17-2015 FAIR PLAY GRADE SCHOOL 301 NORTH WALNUT POTATO MO 99988

Open in new window


Does all the padding (spaces) matter?  or would this be fine:

MM/DD/YY HH:MM:SS ( X) Fire Alarm Y DC1-2346 DC 9-17-2015 FAIR PLAY GRADE SCHOOL 301 NORTH WALNUT POTATO MO 99988

Open in new window

1
csePixelatedAuthor Commented:
Ben 1st can we call em "Account names" or simply "Names" calling them "school names" is throwing me.
 Since everything after the "AcctLineCode","AcctNum" is being replaced then yes everything after that on each line can be purged, however Bill may be correct in assuming this needs to be A PS1
0
Ben Personick (Previously QCubed)Lead Network EngineerCommented:
Based off that, can you please give me the paths to the source file you wish to clean and the subdata.csv file?  I'll put them into my script so all you need to do is run it and check if the output needs any tweaking.

thanks,

Ben
0
csePixelatedAuthor Commented:
I will have to heavily modify them as the csv contains a lot of data i can not reveal, the other reason im leaning to PS1 is that i do have another modification I would like to make, I figured i'd be able to figure it out if i had this to mess with.
0
Ben Personick (Previously QCubed)Lead Network EngineerCommented:
I'm only asking for the paths so I can put them in my script so you don't have to, I'm not asking to see any data :)

IE

what is the path for the file with this data:

Source Data:
02/01/18 10:11:55 ( 0) Fire Alarm      3          DS-5382 XXXXXXXXXX 
02/01/18 10:12:38 ( 0) Fire Alarm      2          DS-3682 XXXXXXXXXX
02/01/18 10:12:38 ( 0) Fire Alarm      4          DS-3234 XXXXXXXXXX 
02/01/18 10:14:16 ( 0) Panic Alarm     2          DSA-3382 WUBBLU, DO

Open in new window


and the path for this subdata.csv file:

Source data:
AccountID,AcctLineCode,AcctNum,AcctNumArea,RadioAcctLineCode,RadioAcctNum,Name,Address,City,State,Zip,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,
1,DR1,14,,,,MALCOM X,12640 SOUTH HWY 63,MISSISSIPPI,TX,88888,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,
2,DC1,2346,,,,DC 9-17-2015 FAIR PLAY GRADE SCHOOL,301 NORTH WALNUT,POTATO,MO,99988,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,
4,DSA,3382,,,,"WUBBLU, DON & TOM",17699 MARBEL ROAD 519,WITCHY,WC,78899,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,

Open in new window


and a path where you want to have this output:

Output data:
02/01/18 10:11:55 ( 0) Fire Alarm      3          DS-5382 XXXXXXXXXXXXX 56789 REAL STREET NAME NOTOWN QL 12345 
02/01/18 10:12:38 ( 0) Fire Alarm      2          DS-3682 XXXXXXXXXXXXXXXXXXXXXX 11135 ANOTHER STREET NAME SOMETOWN HI 12345
02/01/18 10:12:38 ( 0) Fire Alarm      4          DS-3234 XXXXXXXXXXXXX 1 REAL STREET NAME ATOWN CA 12345 
02/01/18 10:14:16 ( 0) Panic Alarm     2          DSA-3382 WUBBLU, DON & TOM 17699 MARBEL ROAD 519 WITCHY WC 78899

Open in new window

0
csePixelatedAuthor Commented:
CSV Z:\OP\CSV\SUBDATA.CSV
source Z:\OP\test.txt
0
Ben Personick (Previously QCubed)Lead Network EngineerCommented:
I'm only asking for the paths so I can put them in my script so you don't have to, I'm not asking to see any data :)

I realize you have given the path though:  "Z:\OP\CSV"


  So all I need to know is

what is the nme of this file:

Source Data:
02/01/18 10:11:55 ( 0) Fire Alarm      3          DS-5382 XXXXXXXXXX 
02/01/18 10:12:38 ( 0) Fire Alarm      2          DS-3682 XXXXXXXXXX
02/01/18 10:12:38 ( 0) Fire Alarm      4          DS-3234 XXXXXXXXXX 
02/01/18 10:14:16 ( 0) Panic Alarm     2          DSA-3382 WUBBLU, DO

Open in new window

0
csePixelatedAuthor Commented:
source Z:\OP\test.txt
0
csePixelatedAuthor Commented:
Bill here is a larger sampling of the original output ( before it was filtered
0
csePixelatedAuthor Commented:
or not...
0
csePixelatedAuthor Commented:
ok this is relatively clean, it also shows i may have some discrepancies to what i said before, after the 51st character cut off after the 1st " " (space) as some are shorter or longer than i previously specified.
02-01-18.P02.xlsx
0
Ben Personick (Previously QCubed)Lead Network EngineerCommented:
@csePixelated

I have here working code along with the examples I used.


Script:


REM Script: FixCSVOutput.cmd
REM Version: 1.5.0
@(
	SETLOCAL ENABLEDELAYEDEXPANSION
	ECHO OFF
	SET "_Null=@@@@@"
	REM SET "_Path=%~dp0"
	SET "_Path=Z:\OP\"
	SET "_SourceFile=!_Path!test.txt"
	SET "_CorrelationFile=!_Path!SUBDATA.CSV"
	SET "_OutputFile=!_Path!Output.txt"
	SET "_eLvl=0"
)

CALL :Main %*

(
	ENDLOCAL
	EXIT /B %eLvl%
)
:Main

	REM Ceate variables which hold the school addresses
	CALL :LoadSubData

	REM Correlate the address recieved with the variables held in memory and outputs the updated info.
	FOR /F "Tokens=*" %%A IN ('type "%_SourceFile%"') DO (
		SET "_ATmp=%%A"
		FOR /F "Tokens=8*" %%a IN ("%%A") DO (
			CALL SET "_ATmp=!!_ATmp:%%~b=!!"
			CALL :CorrelateData %%a
			ECHO.Results = !_Result!
			ECHO.!_Result!>>"%_OutputFile%"
		)
	)

GOTO :EOF

:CorrelateData
	ECHO.
	ECHO.  Correlating "%*" to the Schools List
	FOR /F "Tokens=1* Delims==" %%A IN ('SET ^|FIND /I "_School_%*"') DO (
		SET "_Result=!_ATmp! %%B"
		GOTO :EOF
	)
GOTO :EOF

:LoadSubData
	ECHO. Load Sub Data FOR %%A IN %_CorrelationFile%
	FOR /F "Tokens=*" %%A IN (%_CorrelationFile%) DO (
		SET "_ATmp=%%A"
		SET "_ATmp=!_ATmp:,,=,@@@@@,!"
		SET "_ATmp=!_ATmp:,,=,@@@@@,!"
		FOR /F "Tokens=2,3,7,8,9,10,11 delims=," %%a IN ("echo !_ATmp!") DO (
			REM ECHO SET "_School_%%~a-%%~b=%%~c %%~d %%~e %%~f %%~g
			SET "_School_%%~a-%%~b=%%c %%d %%e %%f %%g"
			CALL SET "_School_%%~a-%%~b=!!_School_%%~a-%%~b:@@@@@=!!
			REM CALL ECHO "!!_School_%%~a-%%~b!!"
		)
	)
GOTO :EOF

Open in new window


SubData.csv File Contents:
AccountID,AcctLineCode,AcctNum,AcctNumArea,RadioAcctLineCode,RadioAcctNum,Name,Address,City,State,Zip,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,
1,DR1,14,,,,MALCOM X,12640 SOUTH HWY 63,MISSISSIPPI,TX,88888,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,
2,DC1,2346,,,,DC 9-17-2015 FAIR PLAY GRADE SCHOOL,301 NORTH WALNUT,POTATO,MO,99988,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,
4,DSA,3382,,,,"WUBBLU, DON & TOM",17699 MARBEL ROAD 519,WITCHY,WC,78899,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,
5,DS,5382,,,,Address 5 - 1,Address 5 - 2,City 5,State-Code 5,ZipCode 5,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,
6,DS,3682,,,,Address 6 - 1,Address 6 - 2,City 6,State-Code 6,ZipCode 6,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,
7,DS,3234,,,,Address 7 - 1,Address 7 - 2,City 7,State-Code 7,ZipCode 7,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,

Open in new window


test.txt File Conents:

02/01/18 10:11:55 ( 0) Fire Alarm      3          DS-5382 XXXXXXXXXX 
02/01/18 10:12:38 ( 0) Fire Alarm      2          DS-3682 XXXXXXXXXX
02/01/18 10:12:38 ( 0) Fire Alarm      4          DS-3234 XXXXXXXXXX 
02/01/18 10:14:16 ( 0) Panic Alarm     2          DSA-3382 WUBBLU, DO

Open in new window


Output.txt Resulting File Contents:

02/01/18 10:11:55 ( 0) Fire Alarm      3          DS-5382  Address 5 - 1 Address 5 - 2 City 5 State-Code 5 ZipCode 5
02/01/18 10:12:38 ( 0) Fire Alarm      2          DS-3682  Address 6 - 1 Address 6 - 2 City 6 State-Code 6 ZipCode 6
02/01/18 10:12:38 ( 0) Fire Alarm      4          DS-3234  Address 7 - 1 Address 7 - 2 City 7 State-Code 7 ZipCode 7
02/01/18 10:14:16 ( 0) Panic Alarm     2          DSA-3382  "WUBBLU  DON & TOM" 17699 MARBEL ROAD 519 WITCHY WC

Open in new window


Example of running the script from the command line:

2018-02-01-20_00_29-Administrator_-C.png
edit, just changed the path to Z:\OP\
0
Bill PrewCommented:
I took a slightly different approach, see how this goes with your data there.

@echo off
setlocal EnableDelayedExpansion

rem Define file paths to work with
set SubFile=B:\EE\EE29081723\subdata.csv
set InFile=B:\EE\EE29081723\input.txt
set OutFile=B:\EE\EE29081723\output.txt

rem Constants
set NULL=[NULL]
set SPACE=[SPACE]

rem Delete output file if it exists
if exist "%OutFile%" del "%OutFile%"

rem Read each line of input file
for /f "usebackq tokens=*" %%A in ("%InFile%") do (

    rem Parse out the AcctLineCode and AcctNum and format for search of subdata
    set "Line=%%A"
    set "Key=!Line:~50,8!"
    if "!Key:~-1!" EQU " " set Key=!Key:~0,-1!
    set "Key=,!Key:-=,!,"

    rem Try to find this account in the subdata file
    set "Matched="
    for /f "tokens=*" %%B in ('find /i "!Key!"^<"%SubFile%"') do (

        rem Match found, parse the sub data by columns and get the ones we want
        rem Care taken to honor any quoted fields that might contain commas...
        set Matched=Y
        set "Sub=%%B"
        for /l %%i in (1,1,2) do set "Sub=!Sub:,,=,%NULL%,!"
        for /l %%i in (1,1,2) do set "Sub=!Sub: =%SPACE%!"
        set i=0

        rem Concatenate the fields we want
        set "SubInfo="
        for %%C in (!Sub!) do (
            set /a i+=1
            if !i! GEQ 7 if !i! LEQ 11 set "SubInfo=!SubInfo! %%~C"

        )

        rem Clean up the old and merged data a bit
        for /l %%i in (1,1,2) do set "SubInfo=!SubInfo:%NULL%=!"
        for /l %%i in (1,1,2) do set "SubInfo=!SubInfo:%SPACE%= !"
        set "InData=!Line:~0,58!"
        if "!InData:~-1!" EQU " " set "InData=!InData:~0,-1!"

        rem Write merged data
        echo !InData!!SubInfo!>>"%OutFile%"

    )

    rem No match in subdata, write the input line as is
    if not defined Matched echo !Line!>>"%OutFile%"
)

Open in new window


»bp
0
Bill PrewCommented:
@csePixelated,

Are you expecting every input record to be matched to the SUB file?  And what output do you want when there is no match?  No output line; the original input line; or just the "stripped" input line up to about position 58?


»bp
0
Bill PrewCommented:
ok this is relatively clean, it also shows i may have some discrepancies to what i said before, after the 51st character cut off after the 1st " " (space) as some are shorter or longer than i previously specified.
Here is a slight update to handle this.

@echo off
setlocal EnableDelayedExpansion

rem Define file paths to work with
set SubFile=B:\EE\EE29081723\subdata.csv
set InFile=B:\EE\EE29081723\input.txt
set OutFile=B:\EE\EE29081723\output.txt

rem Constants
set NULL=[NULL]
set SPACE=[SPACE]

rem Delete output file if it exists
if exist "%OutFile%" del "%OutFile%"

rem Read each line of input file
for /f "usebackq tokens=*" %%A in ("%InFile%") do (

    rem Parse out the AcctLineCode and AcctNum and format for search of subdata
    set "Line=%%A"
    set "InData=!Line:~0,50!"
    for /f "tokens=1" %%K in ("!Line:~50!") do set "Acct=%%K"
    set "Key=,!Acct:-=,!,"

    rem Try to find this account in the subdata file
    set "Matched="
    for /f "tokens=*" %%B in ('find /i "!Key!"^<"%SubFile%"') do (

        rem Match found, parse the sub data by columns and get the ones we want
        rem Care taken to honor any quoted fields that might contain commas...
        set Matched=Y
        set "Sub=%%B"
        for /l %%i in (1,1,2) do set "Sub=!Sub:,,=,%NULL%,!"
        for /l %%i in (1,1,2) do set "Sub=!Sub: =%SPACE%!"
        set i=0

        rem Concatenate the fields we want
        set "SubInfo="
        for %%C in (!Sub!) do (
            set /a i+=1
            if !i! GEQ 7 if !i! LEQ 11 set "SubInfo=!SubInfo! %%~C"
        )

        rem Clean up the old and merged data a bit
        for /l %%i in (1,1,2) do set "SubInfo=!SubInfo:%NULL%=!"
        for /l %%i in (1,1,2) do set "SubInfo=!SubInfo:%SPACE%= !"

        rem Write merged data
        echo !InData!!Acct!!SubInfo!>>"%OutFile%"

    )

    rem No match in subdata, write the input line as is
    if not defined Matched echo !InData!!Acct!>>"%OutFile%"
)

Open in new window


»bp
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
Ben Personick (Previously QCubed)Lead Network EngineerCommented:
Glad to help :)
1
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Windows Batch

From novice to tech pro — start learning today.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.