You also talk about csv files. I can't see any commas, so it isn't a "real" csv file! What else is the data separator? In case it is a tab then note that the forum software doesn't display it. Again: We need to know the data separator!
Regards
aGerman
Delete rows from csv file when column value is not equal to
Moderator: DosItHelp
Re: Delete rows from csv file when column value is not equal
Thanks for quick respond german.
Yes it is comma separator.
Yes it is comma separator.
Re: Delete rows from csv file when column value is not equal
OK. Means, if you open you csv file using a text editor it looks like that
In this case you could use that
Regards
aGerman
Code: Select all
ap,ch,rum,sun,ka,jan,jim,bin,sin
kl,ka,kim,rim,ka,jan,jim,ap,bun
tn,kk,lun,sun,kl,nem,jim,bin,bun
In this case you could use that
Code: Select all
@echo off &setlocal
>"new.csv" type nul
for /f "usebackq tokens=1-8* delims=," %%a in ("sat.csv") do (
if "%%h"=="ap" (
>>"new.csv" echo %%a,%%b,%%c,%%d,%%e,%%f,%%g,%%h,%%i
)
)
Regards
aGerman
Re: Delete rows from csv file when column value is not equal
Thanks agreman
thank you very much , i will try it and confirm you.
thank you very much , i will try it and confirm you.
Re: Delete rows from csv file when column value is not equal
Thanks agerman
Its working fine........i got another doubt but i will post it in related forum.......thanks for your quick support.
Its working fine........i got another doubt but i will post it in related forum.......thanks for your quick support.
Re: Delete rows from csv file when column value is not equal
hi agerman,
now i am facing another problem...
FINDSTR /C:"TN", channelTransaction*.csv | FINDSTR /C:"O2C" | FINDSTR /C:"TRANSFER" > O2CTESTTN.CSV
> TN\TN_south_%gg%\TN\O2C\O2C.csv type nul
for /f "usebackq tokens=1-8* delims=," %%a in ("O2CTESTTN.csv") do (
if "%%f"=="TN" (
>> TN\TN_south_%gg%\TN\O2C\O2C.csv echo %%a,%%b,%%c,%%d,%%e,%%f,%%g,%%h,%%i
)
)
if all the column contains data then the ouput is coming..........if a column is blank then the output not coming.
example:
sat ran fun gun gim TN asm
sat blank fav cou rum TN ss
output should be:
it should print both the line .
but its printing only first line.
and if any of the column is empty its not printing that row.
now i am facing another problem...
FINDSTR /C:"TN", channelTransaction*.csv | FINDSTR /C:"O2C" | FINDSTR /C:"TRANSFER" > O2CTESTTN.CSV
> TN\TN_south_%gg%\TN\O2C\O2C.csv type nul
for /f "usebackq tokens=1-8* delims=," %%a in ("O2CTESTTN.csv") do (
if "%%f"=="TN" (
>> TN\TN_south_%gg%\TN\O2C\O2C.csv echo %%a,%%b,%%c,%%d,%%e,%%f,%%g,%%h,%%i
)
)
if all the column contains data then the ouput is coming..........if a column is blank then the output not coming.
example:
sat ran fun gun gim TN asm
sat blank fav cou rum TN ss
output should be:
it should print both the line .
but its printing only first line.
and if any of the column is empty its not printing that row.
Re: Delete rows from csv file when column value is not equal
I know this problem. We split the line on each found comma. The problem is that the cmd interpretes ",," like a single comma. I have no clean solution for this problem. The only thing we could do is to replace ",," by ", ," and reverse this after process the line.
Untested:
Regards
aGerman
Untested:
Code: Select all
setlocal EnableDelayedExpansion
for /f "usebackq delims=" %%a in ("O2CTESTTN.csv") do (
set "line=%%a"
set "line=!line:,,=, ,!"
set "line=!line:,,=, ,!"
for /f "tokens=1-8* delims=," %%b in ("!line!") do (
if "%%g"=="TN" (
set "newLine=%%b,%%c,%%d,%%e,%%f,%%g,%%h,%%i,%%j"
set "newLine=!newLine:, ,=,,!"
set "newLine=!newLine:, ,=,,!"
>> TN\TN_south_%gg%\TN\O2C\O2C.csv echo\!newLine!
)
)
)
endlocal
Regards
aGerman
Re: Delete rows from csv file when column value is not equal
Thanks agerman
its working
now i going to change all my coding to this one
its working
now i going to change all my coding to this one