Hello
I am an Architect and not a windows batch scripter and I need help to write a small script to remove header and footer of a csv file located in a specific directory and also I should remove an unwanted field from the list of fields.
Please help me on this .
Many Thanks
sheku
Removing header and trailer row, removing field in csv file
Moderator: DosItHelp
Removing header and trailer row, removing field in csv file
Re: Removing header and trailer row, removing field in csv f
Please explain the task with examples.
Re: Removing header and trailer row, removing field in csv f
Would need to see an example of the data before any of us could help you.
Re: Removing header and trailer row, removing field in csv f
Hi Sorry for the delayed reply .
File looks like below, it is a .csv file, I should remove header, trailer and "ID" field with value from the file.
0HEADER20140930-100111,,,,,,,
Date,Exch,Product,ID,Price,Multiplier,Account,Tax
20140930,20Y ,ABC ,1.1112E+11,1000,10,12347890,30
9TRAILER00000004,,,,,,,
Re: Removing header and trailer row, removing field in csv f
ID - 1.1112E+11 - is a 11 digit number
Re: Removing header and trailer row, removing field in csv f
Will any of the fields ever have empty data?
Re: Removing header and trailer row, removing field in csv f
Yes. fields can be empty.
Re: Removing header and trailer row, removing field in csv f
Here is a robust solution for the data you have shown:
This uses a helper batch file called `findrepl.bat` (by aacini) - download from: https://www.dropbox.com/s/rfdldmcb6vwi9xc/findrepl.bat
Place `findrepl.bat` in the same folder as the batch file or on the path.
Code: Select all
type "file.csv"|findrepl /o:2:-2 |findrepl "(.*?,.*?,.*?,).*?,(.*)" "$1$2" >"newfile.csv"
This uses a helper batch file called `findrepl.bat` (by aacini) - download from: https://www.dropbox.com/s/rfdldmcb6vwi9xc/findrepl.bat
Place `findrepl.bat` in the same folder as the batch file or on the path.
Re: Removing header and trailer row, removing field in csv f
Thank you very much. I will try it and respond back.
Re: Removing header and trailer row, removing field in csv f
Hi foxidrive
This is the example data I have provided. I get more rows every day in a single file with header and footer. I believe the solution provided to me will work for more rows
This is the example data I have provided. I get more rows every day in a single file with header and footer. I believe the solution provided to me will work for more rows
Re: Removing header and trailer row, removing field in csv f
It will also work for more rows and more columns, as long as the format of the data is the same.
Re: Removing header and trailer row, removing field in csv f
Hi
I do not have access to dropbox and I could not get the file( repl.bat)
instead I found another link in the net as below and I tried creating a batch file(repl.bat) based on it but not succeded. Error came as shown as below
Please correct me what I have done wrong.
Thanks
Sheku
F:\>type "file.csv"|findrepl /o:2:-2 |findrepl "(.*?,.*?,
.*?,).*?,(.*)" "$1$2" >"newfile.csv"
'findrepl' is not recognized as an internal or external command,
operable program or batch file.
Re: Removing header and trailer row, removing field in csv f
Search this forum for FINDREPL.BAT
You got the wrong helper batch file.
You got the wrong helper batch file.
Re: Removing header and trailer row, removing field in csv f
Hi I copied the code from the below link and created findrepl.bat and got the below error. My file.csv looks like below
F:\>type "file.csv"|findrepl /o:2:-2 |findrepl "(.*?,.*?,
.*?,).*?,(.*)" "$1$2" >"newfile.csv"
ERROR: Insufficient arguments. Use REPL /? to get help.
0HEADER20140930-100111,,,,,,,
Date,Exch,Product,ID,Price,Multiplier,Account,Tax
20140930,20Y ,ABC ,1.1112E+11,1000,10,12347890,30
9TRAILER00000004,,,,,,,
Re: Removing header and trailer row, removing field in csv f
vsmeruga wrote:Hi I copied the code from the below link and created findrepl.bat and got the below error. My file.csv looks like below
You are still using the wrong batch file.ERROR: Insufficient arguments. Use REPL /? to get help.