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

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

#1 Post by Matt20687 » 04 May 2012 14:16

Hello,

I am a little stuck making a batch file for work. The intention of this batch is to change the status of something on a web based form. I have managed to build the menu, sort the GOTO part and then have the user input a prefix, the next part is highlighted in red below, i would like to be able to copy a cell (A1 is fine) in a .csv file and set it as a variable. Is this possible?

:: UnreportBatchFile MM
@echo off

title Unreporting/Assigning Assitance


echo.
echo --------------------------------------------------------------------------
echo This batch file is used to unreport your exams or assign
echo to a specific radiologist
echo --------------------------------------------------------------------------

:MENU

echo.
echo 1 - Unreport Exams
echo 2 - Assign Exams
echo x - Exit
echo.

set /P M=Type 1 or 2 then press ENTER....
if %M%==1 GOTO PREFIX
if %M%==2 GOTO ASSIGN
if %M%==x exit
cls

echo Sorry,'%M%' is not recognised. Please try again...
echo.
goto MENU

:PREFIX

set /P prefix=Please enter the sites prefix:

:IMS

start chrome.exe http://website=%prefix%-%NEED TO COPY AND PASTE FROM CSV%&op=exams

pause > nul
:ASSIGN

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

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

#2 Post by Matt20687 » 04 May 2012 15:34

I can easily pull the information from a .txt file it if is easier?

There would be a list of ids such as:

abc123
abc1234
acb324

Is there anything anyone can think of? I basically would like to copy for example abc123 and then paste it into the address bar in the appropriate place

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

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

#3 Post by Squashman » 04 May 2012 16:28

set /p id=<ID.txt

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

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

#4 Post by Matt20687 » 04 May 2012 16:38

That works a treat Squashman :)

that only reads the first line right?

If that is true (which is what it is doing now) then how would you suggest i coded it to do the same thing for sake of a number 5 IDs. Would i have to have a separate text file for each id?

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

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

#5 Post by Squashman » 04 May 2012 16:58

This can be done with a csv file as well. So if the id is the first variable in your csv.

Code: Select all

for /f "tokens=1* delims=," %%G in (ID.csv) do (
Start chrome ......
)

%%G is the variable you use for the ID.

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

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

#6 Post by foxidrive » 04 May 2012 17:50

Matt20687 wrote:how would you suggest i coded it to do the same thing for sake of a number 5 IDs



This variation of Squashman's code will work if you want to use every line in the text file.

Code: Select all

for /f "delims=" %%G in (ID.csv) do (
Start chrome ......
)

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

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

#7 Post by Matt20687 » 05 May 2012 01:19

It seems to be following the logic but not working properly. The script has recognised there are 4 ids within the .csv and opens 4 seperate tabs on google chrome with the correct link and such like, the only problem is is that it is only copying and pasting the first id in the list of 4, therefore every tab (4 in total) is showing as the same one.

My script is:


: PREFIX

echo.
set /P prefix=Please enter the sites prefix:

:SITE

set dst=c:\users\matthewm\desktop\unreport or assign batch\
set dst2=c:\users\matthewm\desktop\unreport or assign batch\

set /p texte=<unreportid.csv

for /f "tokens=1* delims=," %%G in (unreportid.csv) do (
start chrome.exe "http://WEBSITE=%prefix%-%texte%&op=exams"
)

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

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

#8 Post by Matt20687 » 05 May 2012 03:33

Would it be the delimiter causing issues?

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

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

#9 Post by foxidrive » 05 May 2012 05:49

Try the change below. It expects to use the first four fields in the CSV file, which are delimited by comma


Matt20687 wrote:My script is:


: PREFIX

echo.
set /P prefix=Please enter the sites prefix:

:SITE

set dst=c:\users\matthewm\desktop\unreport or assign batch\
set dst2=c:\users\matthewm\desktop\unreport or assign batch\

for /f "tokens=1-4 delims=," %%a in (unreportid.csv) do (
start "" chrome.exe "http://WEBSITE=%prefix%-%%a&op=exams"
start "" chrome.exe "http://WEBSITE=%prefix%-%%b&op=exams"
start "" chrome.exe "http://WEBSITE=%prefix%-%%c&op=exams"
start "" chrome.exe "http://WEBSITE=%prefix%-%%d&op=exams"
goto :next
)
:next

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

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

#10 Post by Matt20687 » 05 May 2012 06:10

It still is doing the same thing foxidrive. It is searching for each one (4 in total) but again it is using the same ID rather than the 4 separate ones.

My code is:

set /p uid=<unreportid.csv

for /f "tokens=1-4 delims=," %%a in (unreportid.csv) do (
start "" chrome.exe "http://WEBSITE=%prefix%-%uid%&old_patient_id=%prefix%-%uid%&op=exams"
start "" chrome.exe "http://WEBSITE=%prefix%-%uid%&old_patient_id=%prefix%-%uid%&op=exams"
start "" chrome.exe "http://WEBSITE=%prefix%-%uid%&old_patient_id=%prefix%-%uid%&op=exams"
start "" chrome.exe "http://WEBSITE=%prefix%-%uid%&old_patient_id=%prefix%-%uid%&op=exams"
goto :next
)

:next
:next

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

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

#11 Post by Matt20687 » 05 May 2012 16:07

Hello,

I am tearing my hair out over this!! Cannot figure out why it will read all of the entries but not copy/paste any but the first one!

Is there anything anyone can suggest as its holding my whole project up now, i will keep looking but i have been trying to sort it for hours now so not too full of hope :P

Thanks for everything everyone,
Matt

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

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

#12 Post by foxidrive » 05 May 2012 16:47

Matt20687 wrote:It still is doing the same thing foxidrive.

My code is:

set /p uid=<unreportid.csv

for /f "tokens=1-4 delims=," %%a in (unreportid.csv) do (
start "" chrome.exe "http://WEBSITE=%prefix%-%uid%&old_patient_id=%prefix%-%uid%&op=exams"
start "" chrome.exe "http://WEBSITE=%prefix%-%uid%&old_patient_id=%prefix%-%uid%&op=exams"
start "" chrome.exe "http://WEBSITE=%prefix%-%uid%&old_patient_id=%prefix%-%uid%&op=exams"
start "" chrome.exe "http://WEBSITE=%prefix%-%uid%&old_patient_id=%prefix%-%uid%&op=exams"
goto :next
)

:next


Your code doesn't use %%a and %%b and %%c and %%d

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

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

#13 Post by Matt20687 » 05 May 2012 16:56

foxidrive wrote:
Matt20687 wrote:It still is doing the same thing foxidrive.

My code is:

set /p uid=<unreportid.csv

for /f "tokens=1-4 delims=," %%a in (unreportid.csv) do (
start "" chrome.exe "http://WEBSITE=%prefix%-%uid%&old_patient_id=%prefix%-%uid%&op=exams"
start "" chrome.exe "http://WEBSITE=%prefix%-%uid%&old_patient_id=%prefix%-%uid%&op=exams"
start "" chrome.exe "http://WEBSITE=%prefix%-%uid%&old_patient_id=%prefix%-%uid%&op=exams"
start "" chrome.exe "http://WEBSITE=%prefix%-%uid%&old_patient_id=%prefix%-%uid%&op=exams"
goto :next
)

:next


Your code doesn't use %%a and %%b and %%c and %%d


You will have to forgive me, i havent been doing this long!! So are you saying the first line should read:

for /f "tokens=1-4 delims=," %%a %%b %%c %%d in (unreportid.csv) do (

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

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

#14 Post by foxidrive » 05 May 2012 17:39

Nope. Examine the code I provided, based upon your example above.

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

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

#15 Post by Squashman » 05 May 2012 17:46

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.

Post Reply