How can I convert this input from text to a csv file?

I would like to use the following file at C:\Data\Input.txt and then convert it to a csv file.

This is what the input look like.  The actual data will vary, it may be much longer with many more part numbers:

ISA*00*          *00*          *AA*ABCDEF         *00*1234567891     *123456*1234*|*12345*123456789*0*A*>~
GS*PS*1234567891*1234567891*20121116*1234*1234*A*123456ABCD~
ST*830*12345678~
AAA*00*9999999999999999999**BB*B*20121001*20130201*20121002****BB~
N1*SW*COMPANY NAME~
N1*BC*COMPANY.*1*1234567891234~
LIN**ZA*45612378912345***A1*DESC1~
PO4*00~
JKL*101*0*Z*20121001*20121108~
ABC*CD*9*1231235464561*10~
ABC*CD*9*9898988546454*0~
ABC*CD*9*5645645461464*0~
JKL*213*0*Z*20121122*20121107~
ABC*CD*9*5645645461464*0~
ABC*CD*9*1231235464561*15~
ABC*CD*9*9898988546454*0~
LIN**WW*7894561231231***A1*DESC2~
PO4*00~
JKL*545*0*Z*20121001*20121101~
ABC*CD*9*5115151511554*50~
ABC*CD*9*9995989999999*0~
ABC*CD*9*1231235464561*0~
ABC*CD*9*4444555454545*0~
ABC*CD*9*9898988546454*0~
ABC*CD*9*5645645461464*0~
ABC*CD*9*7777787878787*20~
JKL*4545*0*B*20121122*20121124~
ABC*CD*9*1231235464561*0~
ABC*CD*9*4444555454545*10~
ABC*CD*9*9898988546454*0~
ABC*CD*9*5115151511554*0~
ABC*CD*9*5645645461464*0~
ABC*CD*9*9995989999999*0~
ABC*CD*9*7777787878787*1~
CTT*00~
SE*1234*12345678~
GE*0*1234~
IEA*0*123456454~

Open in new window

Output file will be created at:  C:\Data\Output\Output.csv
I would like to use an automated script, perhaps Batch or VBS or Powershell so that the output is a csv file which format looks somewhat like this:

"1","'9999999999999999999","10/1/2012","2/1/2013"
"2","'45612378912345"
"3","10","10/1/2012","11/8/2012","'45612378912345","DESC1","'1231235464561"
"3","0","10/1/2012","11/8/2012","'45612378912345","DESC1","'9898988546454"
"3","0","10/1/2012","11/8/2012","'45612378912345","DESC1","'5645645461464"
"3","0","11/22/2012","11/7/2012","'45612378912345","DESC1","'5645645461464"
"3","15","11/22/2012","11/7/2012","'45612378912345","DESC1","'1231235464561"
"3","0","11/22/2012","11/7/2012","'45612378912345","DESC1","'9898988546454"
"2","'7894561231231"
"3","50","10/1/2012","11/1/2012","'7894561231231","DESC2","'5115151511554"
"3","0","10/1/2012","11/1/2012","'7894561231231","DESC2","'9995989999999"
"3","0","10/1/2012","11/1/2012","'7894561231231","DESC2","'1231235464561"
"3","0","10/1/2012","11/1/2012","'7894561231231","DESC2","'4444555454545"
"3","0","10/1/2012","11/1/2012","'7894561231231","DESC2","'9898988546454"
"3","0","10/1/2012","11/1/2012","'7894561231231","DESC2","'5645645461464"
"3","20","10/1/2012","11/1/2012","'7894561231231","DESC2","'7777787878787"
"3","0","11/22/2012","11/24/2012","'7894561231231","DESC2","'1231235464561"
"3","10","11/22/2012","11/24/2012","'7894561231231","DESC2","'4444555454545"
"3","0","11/22/2012","11/24/2012","'7894561231231","DESC2","'9898988546454"
"3","0","11/22/2012","11/24/2012","'7894561231231","DESC2","'5115151511554"
"3","0","11/22/2012","11/24/2012","'7894561231231","DESC2","'5645645461464"
"3","0","11/22/2012","11/24/2012","'7894561231231","DESC2","'9995989999999"
"3","1","11/22/2012","11/24/2012","'7894561231231","DESC2","'7777787878787"

Open in new window

Thank you for your assistance.
100questionsAsked:
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.

NVITCommented:
@echo off
setlocal enabledelayedexpansion
set FNOut=output.txt
for /f "tokens=1-9 delims=*" %%a in (input.txt) do (
  set new="%%a","%%b","%%c","%%d","%%e","%%f","%%g","%%h","%%i"
  set fix=!new:,""=!
  >> "%FNOut%" echo !fix!
)

Open in new window

0
Bill PrewCommented:
Give this a try, as long as the data behaves similar to your example I think it should get the job done.

@echo off
setlocal EnableDelayedExpansion

set InFile=in.txt
set OutFile=out.txt

(
  for /f "usebackq tokens=1-9 delims=*~" %%a in ("%InFile%") do (
    if "%%a" == "AAA" (
      call :FormatDate "%%f" & set AAA_f=!DateOut!
      call :FormatDate "%%g" & set AAA_g=!DateOut!
      echo "1","'%%c","!AAA_f!","!AAA_g!"
    )
    if "%%a" == "LIN" (
      echo "2","'%%c"
      set LIN_c=%%c
      set LIN_e=%%e
    )
    if "%%a" == "JKL" (
      call :FormatDate "%%e" & set JKL_e=!DateOut!
      call :FormatDate "%%f" & set JKL_f=!DateOut!
    )
    if "%%a" == "ABC" (
      echo "3","%%e","!JKL_e!","!JKL_f!","'!LIN_c!","!LIN_e!","'%%d"
    )
  )
)>"%OutFile%"
exit /b

:FormatDate [yyyymmdd]
  set DateIn=%~1
  set y=!DateIn:~0,4!
  set /a m=1!DateIn:~4,2!-100
  set /a d=1!DateIn:~6,2!-100
  set DateOut=!m!/!d!/!y!
  exit /b

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
100questionsAuthor Commented:
Excellent work, thank you.
0
Bill PrewCommented:
Welcome, glad that was useful.

~bp
0
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.