For example adding 816 to each row on AL:

Moderator: DosItHelp
Code: Select all
@echo off
:: %1 is the input filename
:: %2 is the new column header
:: %3 is the dummy number to fill every cell in the new column
setlocal
set "file=%~1"
set "fileout=newfile.csv"
set /p "var="<"%file%" >nul
>"%fileout%" echo.%var%,%2
for /f "skip=1 delims=" %%a in ('type "%file%"') do (
>>%fileout% echo.%%a,%3
)
Code: Select all
@echo off
for /f "delims=" %%a in ('type "file.csv"') do (
>>"fileout.csv" echo.%%a,816
)
foxidrive wrote:When you say 'last empty column' I assume that no other columns with data appear after the last empty one.
Try this:Code: Select all
@echo off
for /f "delims=" %%a in ('type "file.csv"') do (
>>"fileout.csv" echo.%%a,816
)
Code: Select all
@echo off
for /f "delims=" %%a in ('type "file.csv"') do (
>>"fileout.csv" echo.816,%%a
)
MostWired wrote:this worked for me too.
But also wondering how can an existing empty column be populated with data?
or how do I add data to column 4?
I also need to strip the beginning and ending zeros from a field. example: 0123450, it's always 7 char long with zero at beginning and end.
Code: Select all
@echo off
del "newfile.csv" 2>nul
for /f "tokens=1,2,3,4,* delims=," %%a in ('type "file.csv"') do (
>>"newfile.csv" echo.%%a,%%b,%%c,%%d,%time%,%%e
)
Code: Select all
@echo off
setlocal EnableExtensions EnableDelayedExpansion
del "newfile.csv" 2>nul
for /f "tokens=1,2,* delims=," %%a in ('type "file.csv"') do (
set var=%%b
set var=!var:~1,-1!
>>"newfile.csv" echo.%%a,!var!,%%c
)