You may change the way to split your values. Instead of using a for /F "tokens=...
command, you may use a regular for
command that iterates over the values and use they to assemble the output line. However, this works only if the values have certain form. In the example below I assumed that the values have not quotes nor exclamation marks nor carets nor wild-cards (?
or *
); these points may be fixed, but with more code...
EDIT: I modified the code in order to get a limited number of fields.
@echo off
setlocal EnableDelayedExpansion
REM set "sourcedir=C:\Users\aborgetti\Desktop\Pipe Delimiter Project"
REM set "destdir=C:\Users\aborgetti\Desktop\Pipe Delimiter Project"
set "max=%1"
if not defined max set max=99
for /F "usebackq delims=" %%a in ("test.txt") do (
set "input=%%a"
set "output=|"
set i=0
for %%b in ("!input:|=" "!") do if !i! lss %max% (
set "output=!output!%%~b|"
set /A i+=1
)
echo !output!
)
This is test.txt:
1|2|3|4|5|6|7|8|9|10|11|12|13|14|15|16|17|18|19|20|21|22|23|24|25|26|27|28|29|30|31|32|33|34|35
A|B|C|D|E|F|G|H|I|J|K|L|M|N|O|P|Q|R|S|T|U|V|W|X|Y|Z|a|b|c|d|e|f|g|h|i
35|34|33|32|31|30|29|28|27|26|25|24|23|22|21|20|19|18|17|16|15|14|13|12|11|10|9|8|7|6|5|4|3|2|1
Output example:
C:\> test
|1|2|3|4|5|6|7|8|9|10|11|12|13|14|15|16|17|18|19|20|21|22|23|24|25|26|27|28|29|30|31|32|33|34|35|
|A|B|C|D|E|F|G|H|I|J|K|L|M|N|O|P|Q|R|S|T|U|V|W|X|Y|Z|a|b|c|d|e|f|g|h|i|
|35|34|33|32|31|30|29|28|27|26|25|24|23|22|21|20|19|18|17|16|15|14|13|12|11|10|9|8|7|6|5|4|3|2|1|
C:\> test 26
|1|2|3|4|5|6|7|8|9|10|11|12|13|14|15|16|17|18|19|20|21|22|23|24|25|26|
|A|B|C|D|E|F|G|H|I|J|K|L|M|N|O|P|Q|R|S|T|U|V|W|X|Y|Z|
|35|34|33|32|31|30|29|28|27|26|25|24|23|22|21|20|19|18|17|16|15|14|13|12|11|10|
C:\> test 7
|1|2|3|4|5|6|7|
|A|B|C|D|E|F|G|
|35|34|33|32|31|30|29|