sorry if this silly questions,
I need to replace delimiter in text file column and data in certain column only.
I already success to replace delimiter from comma to pipe, but not yet on key in data.
THIS IS BATCH FOR REPLACE DELIMETER :
@echo off
setlocal disableDelayedExpansion
set input="PLUIn.txt"
set output="dibalscopitems2.txt"
::There should be a TAB character after the equal below
set "tab=,"
>%output% (
for /f "delims=" %%A in ('findstr /rn "^" %input%') do (
set ln=%%A
setlocal enableDelayedExpansion
set "ln=!ln:*:=!"
if defined ln set "ln=!ln:%tab%=|!"
echo(!ln!
endlocal
)
)
THE QUESTION IS : For text file, i want to key in certain column only, and the rest column will auto generate.
As sample below :
Key in text file : 00001,1,7.50,APPLE,APPLE,0,0
Result after run batch : M|00001|1|7.50|APPLE|APPLE|0|0|21|2|1|0.00|000|000|0||2|45|1|
So I only key in item in highlight on blue in images. Refer this image
DETAILED COLUMN :
M|00001|1|7.50|AYAM SEGAR||0|0|21|2|1|0.00|000|000|0||2|45|1|
M|00002|2|6.99|APPLE||1|0|21|2|1|0.00|000|000|0||2|45|1|
M|00003|3|9.99|SIAKAP||1|0|21|2|1|0.00|000|000|0||2|45|1|
M|00004|4|1.99|ORANGE||1|0|21|2|1|0.00|000|000|0||2|45|1|
M|00005|5|12.99|KEMBUNG||0|0|21|2|1|0.00|000|000|0||2|45|1|
- A,B @ M - A(add), B(Remove), M(modify)
- Plu No - Max 6 digits
- Hotkey - Max 3 digits
- Unit price - 0.00
- Name - 20 characters
- Name2 - dummy
- Weight unit - 0=weight / 1=pcs
- Section (barcode structure no - 1=weight / 2=pcs
- Label Format - dummy
- EAN Format - dummy
- Vat Type - dummy
- Offer Price - dummy
- Expiry Date - 001 = 1 days
- Extra Date - dummy
- Tare - dummy
- EAN Scannner - dummy
- Product Class - dummy
- Product Direct Number - dummy
- Overwrite Price - 0=allow / 1=notallow
- G Text - dummy
INPUT FILES :
M,00001,1,7.50,AYAM SEGAR,,0,0,
M,00002,2,6.99,APPLE,,1,0,
M,00003,3,9.99,SIAKAP,,1,0,
M,00004,4,1.99,ORANGE,,1,0,
M,00005,5,12.99,KEMBUNG,,0,0,
RESULT AFTER RUN :
M|00001|1|7.50|AYAM SEGAR||0|0|21|2|1|0.00|000|000|0||2|45|1|
M|00002|2|6.99|APPLE||1|0|21|2|1|0.00|000|000|0||2|45|1|
M|00003|3|9.99|SIAKAP||1|0|21|2|1|0.00|000|000|0||2|45|1|
M|00004|4|1.99|ORANGE||1|0|21|2|1|0.00|000|000|0||2|45|1|
M|00005|5|12.99|KEMBUNG||0|0|21|2|1|0.00|000|000|0||2|45|1|
ON INPUT FILES, we do not want to key in all column, as some column we do not use it.so from column no 9 until last, the values is not changed. we want to key in from column 1 until 8.
Thank you
CodePudding user response:
Ok, here we go...
PLUIn.txt the input file:
M,00001,1,7.50,AYAM SEGAR,,0,0,
M,00002,2,6.99,APPLE,,1,0,
M,00003,3,9.99,SIAKAP,,1,0,
M,00004,4,1.99,ORANGE,,1,0,
M,00005,5,12.99,KEMBUNG,,0,0,
The Batch file program:
@echo off
setlocal EnableDelayedExpansion
set "data=21|2|1|0.00|000|000|0||2|45|1|"
(for /F "delims=" %%a in (PLUIn.txt) do (
set "line=%%a"
echo !line:,=^|!!data!
)) > dibalscopitems2.txt
dibalscopitems2.txt the output file:
M|00001|1|7.50|AYAM SEGAR||0|0|21|2|1|0.00|000|000|0||2|45|1|
M|00002|2|6.99|APPLE||1|0|21|2|1|0.00|000|000|0||2|45|1|
M|00003|3|9.99|SIAKAP||1|0|21|2|1|0.00|000|000|0||2|45|1|
M|00004|4|1.99|ORANGE||1|0|21|2|1|0.00|000|000|0||2|45|1|
M|00005|5|12.99|KEMBUNG||0|0|21|2|1|0.00|000|000|0||2|45|1|
Some suggestions when you request technical aid:
You should describe your problem in terms as clear and concise as possible. Do not insert additional information not related to the problem that just could confuse! For example:
Where is the input data?
I want to key in certain column only
Ok. How is such data?
Because some column we do not use it, the rest column will auto generate.
("auto generate"? using which formula?) Ok, ok... I don't care if you want or want not to enter data, nor if you "key in" such a data or it magically appears in a file. Do you have a file with the data? How is it?
M,00001,1,7.50,AYAM SEGAR,,0,0,
And the output?
M|00001|1|7.50|AYAM SEGAR||0|0|21|2|1|0.00|000|000|0||2|45|1|
Ok. Thanks a lot!
EDIT 2021/09/27: Modified program as requested in comment
New PLUIn.txt input file:
M,00001,1,7.50,AYAM SEGAR,,0,0,1
M,00002,2,6.99,APPLE,,1,0,12
M,00003,3,9.99,SIAKAP,,1,0,123
M,00004,4,1.99,ORANGE,,1,0,555
M,00005,5,12.99,KEMBUNG,,0,0,999
New program.bat:
@echo off
setlocal EnableDelayedExpansion
set "data=|21|2|1|0.00|HERE|000|0||2|45|1|"
(for /F "delims=" %%a in (PLUIn.txt) do (
set "line=%%a|"
for /F "tokens=7* delims=," %%b in ("%%a") do (
set "line=!line:,%%c|=!"
echo !line:,=^|!!data:HERE=%%c!
)
)) > dibalscopitems2.txt
New dibalscopitems2.txt output file:
M|00001|1|7.50|AYAM SEGAR||0|0|21|2|1|0.00|1|000|0||2|45|1|
M|00002|2|6.99|APPLE||1|0|21|2|1|0.00|12|000|0||2|45|1|
M|00003|3|9.99|SIAKAP||1|0|21|2|1|0.00|123|000|0||2|45|1|
M|00004|4|1.99|ORANGE||1|0|21|2|1|0.00|555|000|0||2|45|1|
M|00005|5|12.99|KEMBUNG||0|0|21|2|1|0.00|999|000|0||2|45|1|