0

I need to know if it's possible to create a batch .bat file to extract from a .csv several rows and save these selected rows into another .csv file. I have read another topics on this webpage and i can only find how to split my csv in several files cutting it by a defined number of rows (for example cutting it in csv files of 500 rows max.).

In the csv files which i would like to manage there are several rows of data with the same structure.

I want to extract into another .csv file some rows of these filtering by a ticket number which is located in each row at a certain position. I don't want to make any change at the original file where the files will be exported, I only want to copy these files into another .csv. For example if i have these rows:

19/09/2013 123456789
19/09/2013 231564215
19/09/2013 456464231
19/09/2013 564659832
19/09/2013 000000054

As is shown, the ticket numbers is located always between the 12th and the 21st position. In this example i want to extract to another csv file the rows with the ticket numbers "231564215" and "564659832". So the data inside the new .csv file must be:

19/09/2013 231564215
19/09/2013 564659832

I need the script to ask you for the name of the original file from where you want to extract and save the data, and obviously to ask you for the number of the tickets you would like to extract (separated by carriage returns for example). The sequence i will like to get is something like this:

CMD Says: Please select the file you would like to convert
I type: c:/Documents and setting/Marta/testFile.csv
CMD Says: Please enter the list of tickets you want to export
I type: 231564215
564659832
CMD Says: Exporting data...
CMD: Export process finished. Your new file is c:/Documents and setting/Marta/exportedData.csv

NB: Sorry for my poor English, I'm Spanish

4

1 回答 1

0

已编辑

根据您提供的示例文件,所需的数字不能与每条记录的任何其他部分混合,因此这将返回您需要的数据:

@echo off
( for /f "usebackq delims=" %%a in ("Ticket Numbers.txt") do find ",%%a," <"originalFile.csv"  )>"newfile.csv"

这是将数据放入新文件的有用方法吗?

于 2013-10-15T13:39:56.687 回答