-2

I need help to write a batch file that can do fill the blank.

File like this:

~E-00001~|~E-0000001.pdf~|~C:\2014\text\~
~E-00002~|~~|~~
~E-00003~|~~|~~
~E-00004~|~E-0000002.pdf~|~C:\2014\text\02~
~E-00005~|~~|~~
~E-00006~|~~|~~
~E-00007~|~E-0000003.pdf~|~C:\2014\text\03~
~E-00008~|~~|~~
~E-00009~|~~|~~

Will look like this:

~E-00001~|~E-0000001.pdf~|~C:\2014\text\~
~E-00002~|~E-0000001.pdf~|~C:\2014\text\~
~E-00003~|~E-0000001.pdf~|~C:\2014\text\~
~E-00004~|~E-0000002.pdf~|~C:\2014\text\02~
~E-00005~|~E-0000002.pdf~|~C:\2014\text\02~
~E-00006~|~E-0000002.pdf~|~C:\2014\text\02~
~E-00007~|~E-0000003.pdf~|~C:\2014\text\03~
~E-00008~|~E-0000003.pdf~|~C:\2014\text\03~
~E-00009~|~E-0000003.pdf~|~C:\2014\text\03~

Thank You!!!

2
  • Where will you get the data that should be in the file? e.g. how does E-00005 tell you it is C:\2014\text\02? Is it because the one above it is? Apr 23, 2014 at 15:03
  • Yes just read the one above and fill below until the next one and on.
    – user317769
    Apr 23, 2014 at 15:19

1 Answer 1

1

I'm not entirely sure about your requirement (see my comment to your OP), but my gut says you probably want a batch file, such as:

added note by barlop- jimbob has spotted that this pattern is or can be accomplished by replacing the double tildas.

@ECHO OFF
SETLOCAL

set LAST_A=
set LAST_B=
set LAST_C=

FOR /f "tokens=1,2,3 delims=|" %%A IN (%1) DO CALL :write %%A %%B %%C
GOTO :eof

:write
SET A=%1
SET B=%2
SET C=%3

IF "{%A%}"=="{~~}" SET A=%LAST_A%
IF "{%B%}"=="{~~}" SET B=%LAST_B%
IF "{%C%}"=="{~~}" SET C=%LAST_C%

ECHO %A%^|%B%^|%C%

SET LAST_A=%A%
SET LAST_B=%B%
SET LAST_C=%C%
GOTO :eof

...which you would call with:

x:\pathto\process_file.cmd X:\pathto\inputfile > X:\pathto\outputfile

Test this carefully, though...

Added by barlop

J:\>type a.a
~E-00001~|~E-0000001.pdf~|~C:\2014\text\~
~E-00002~|~~|~~
~E-00003~|~~|~~
~E-00004~|~E-0000002.pdf~|~C:\2014\text\02~
~E-00005~|~~|~~
~E-00006~|~~|~~
~E-00007~|~E-0000003.pdf~|~C:\2014\text\03~
~E-00008~|~~|~~
~E-00009~|~~|~~
J:\>a.bat a.a
~E-00001~|~E-0000001.pdf~|~C:\2014\text\~
~E-00002~|~E-0000001.pdf~|~C:\2014\text\~
~E-00003~|~E-0000001.pdf~|~C:\2014\text\~
~E-00004~|~E-0000002.pdf~|~C:\2014\text\02~
~E-00005~|~E-0000002.pdf~|~C:\2014\text\02~
~E-00006~|~E-0000002.pdf~|~C:\2014\text\02~
~E-00007~|~E-0000003.pdf~|~C:\2014\text\03~
~E-00008~|~E-0000003.pdf~|~C:\2014\text\03~
~E-00009~|~E-0000003.pdf~|~C:\2014\text\03~

J:\>  
can do J:\>a.bat a.a >a.b   thus giving that output in a.b
1
  • jimbobmcgee its work fine thank you very much!
    – user317769
    Apr 23, 2014 at 16:29

Not the answer you're looking for? Browse other questions tagged .