Batch File - Can you search a .csv and paste ??

Discussion forum for all Windows batch related topics.

Moderator: DosItHelp

Message
Author
Matt20687
Posts: 54
Joined: 02 May 2012 14:42

Re: Batch File - Can you search a .csv and paste ??

#16 Post by Matt20687 » 06 May 2012 00:09

Squashman wrote:Remember in my example when I told you %%G is the variable you need to use for the ID.

Are you putting all the ids on one line separated by a comma or is this a true csv file and the id is the first field in each line.

Could we see the id file please.


The layout is:

A
1| DF5488
2|4777858
3| 3201V
4| ABC123

As you can see from the above all of the ID's are in column A, column B,C,D etc etc are empty

foxidrive
Expert
Posts: 6031
Joined: 10 Feb 2012 02:20

Re: Batch File - Can you search a .csv and paste ??

#17 Post by foxidrive » 06 May 2012 05:43

Does it have these parts in it?

A
1|
2|
3|
4|


Or is it just this?

DF5488
4777858
3201V
ABC123

Squashman
Expert
Posts: 4472
Joined: 23 Dec 2011 13:59

Re: Batch File - Can you search a .csv and paste ??

#18 Post by Squashman » 06 May 2012 08:27

So it is a PIPE delimited file not a COMMA delimited file?

Matt20687
Posts: 54
Joined: 02 May 2012 14:42

Re: Batch File - Can you search a .csv and paste ??

#19 Post by Matt20687 » 06 May 2012 08:41

Squashman wrote:So it is a PIPE delimited file not a COMMA delimited file?


The pipes are just breaking the row numbers with the actual numbers data. The ids are held in column a and in this example are in rows 1, 2, 3 & 4. The second example foxi gave above.

Squashman
Expert
Posts: 4472
Joined: 23 Dec 2011 13:59

Re: Batch File - Can you search a .csv and paste ??

#20 Post by Squashman » 06 May 2012 09:02

So you are just using a plain text file as your input with the ID's each on their own line.

foxidrive
Expert
Posts: 6031
Joined: 10 Feb 2012 02:20

Re: Batch File - Can you search a .csv and paste ??

#21 Post by foxidrive » 06 May 2012 10:15

It seems so Squashman.
Your first code snippet will work

Code: Select all

@echo off
for /f "delims=" %%G in (ID.csv) do (
start "" chrome.exe "http://WEBSITE=%prefix%-%%G&op=exams"
)



@Matt20687

The file ID.csv file above can be called anything, like file.txt but it needs to have a simple filename, no spaces.
To be clear, this version requires a layout with one entry per line.

Earlier versions were geared to CSV format but you aren't using that, it is clear now.

Matt20687
Posts: 54
Joined: 02 May 2012 14:42

Re: Batch File - Can you search a .csv and paste ??

#22 Post by Matt20687 » 06 May 2012 14:18

foxidrive wrote:It seems so Squashman.
Your first code snippet will work

Code: Select all

@echo off
for /f "delims=" %%G in (ID.csv) do (
start "" chrome.exe "http://WEBSITE=%prefix%-%%G&op=exams"
)



@Matt20687

The file ID.csv file above can be called anything, like file.txt but it needs to have a simple filename, no spaces.
To be clear, this version requires a layout with one entry per line.

Earlier versions were geared to CSV format but you aren't using that, it is clear now.


This is working perfectly now! Thanks.

I assume i could use the same code when i get to the section where i need to read the list of booking numbers? Would i literally do something such as:

set bookingNumber=ACC.csv

for /f "delims=" %%H in (ACC.csv) do (
set searchStr=^^^"');\"><td>%bookingNumber%"
for /f "delims=" %%A in ('findstr /l /c:!searchStr! test.txt') do set ln=%%A
set "ln=!ln:*&sps_id=!"
set "sps_id=!ln:~1,7!"
set sps_id
)

Squashman
Expert
Posts: 4472
Joined: 23 Dec 2011 13:59

Re: Batch File - Can you search a .csv and paste ??

#23 Post by Squashman » 06 May 2012 14:41

It seems you really don't understand how to use the variable from the FOR LOOP at all. If you want to use the Book Number from the file then use the LOOP Variable.
This code:
set bookingNumber=ACC.csv
does nothing for you.

A For /F loop parses an input file. As it is parsing each line it assigns it to the LOOP variable. In your code it would assign it to %%H.

foxidrive
Expert
Posts: 6031
Joined: 10 Feb 2012 02:20

Re: Batch File - Can you search a .csv and paste ??

#24 Post by foxidrive » 06 May 2012 16:06

Matt20687 wrote:
foxidrive wrote:

Code: Select all

@echo off
for /f "delims=" %%G in (ID.csv) do (
start "" chrome.exe "http://WEBSITE=%prefix%-%%G&op=exams"
)




I assume i could use the same code when i get to the section where i need to read the list of booking numbers? Would i literally do something such as:

[snip incorrect code]


It would be best for you to explain what you want to do, in English, and use real text examples, rather than guessing at syntax. We can interpret and try and provide working example code.

If you have a list of booking numbers, one per line, then the same code as above will work, but replace the filename ID.csv with something more descriptive like BookNumbers.txt

The chrome syntax is specific to your web site and none of us know what exactly that is.

foxidrive
Expert
Posts: 6031
Joined: 10 Feb 2012 02:20

Re: Batch File - Can you search a .csv and paste ??

#25 Post by foxidrive » 06 May 2012 16:13

I recall your booking numbers from another thread - you are trying to parse a web page for the number and then you want to use it in the code above it seems.

Batch files cannot work with website URLS and the web page will need to be downloaded and saved using chrome or WGET, which is a command line program for accessing HTTP and FTP protocols.

Once you have the web page on your hard drive then you can use a batch file to extract the booking number and also to later process it in a for in do loop.

Post Reply