Batch to edit column in csv

November 28, 2010 at 16:37:48
Specs: Windows Server 2008 R2
Hi,

I require some assistance modifying a csv using a batch script. I have a csv with details from AD e.g.:

name, department, phone_number
john, IT, +99 9 9999 1234
bob, accounts, +99 9 9999 5678

What I need is a batch script to edit the phone_number column by replacing the full number with the last 4 digits.

name, department, phone_number
john, IT, 1234
bob, accounts, 5678

Your help will be greatly appreciated!


See More: Batch to edit column in csv

Report •


#1
November 28, 2010 at 16:55:28
@echo off & setLocal enableDELAYedeXpansion

for /f "tokens=* delims= " %%a in (my.csv) do (
> new.csv echo.%%a
goto :next
)
:next


for /f "skip=1 tokens=1-3 delims=," %%a in (my.csv) do (
set P=%%c
set P=!P:~-4!
>> new.csv echo.%%a, %%b, !P!
)


=====================================
Life is too important to be taken seriously.

M2


Report •
Related Solutions


Ask Question