0

I need help with this statement at the moment when executed in a batch file it will launch all lines of a text file e.g.

file1.txt:

notepad
wordpad

so it will launch:

start notepad
start wordpad

Although I would like to be able to specify which line it will execute, instead of executing them all (which it is doing at the moment)

for /f "delims=|" %%i in (file1.txt) do @start "x" %%i

Any help would be greatly appreciated

James
  • 227
  • 1
  • 3
  • 6
  • 1
    Take a look at this response for dealing with a specific line number http://stackoverflow.com/questions/2701910/windows-batch-file-to-echo-a-specific-line-number – onteria_ May 13 '11 at 18:13
  • I think they can help you more than us: http://superuser.com/ – BlackBear May 13 '11 at 18:14

1 Answers1

0

If you know the line number you would like to run, you can use something like this:

for /f "tokens=2* delims=]" %%I in ( ' find /V /N "" file1.txt ^| findstr /B /L "[1]" ' ) do @start "x" %%I

find /V /N "" file1.txt -- Displays all lines from file1.txt that are not "" (so basically any line that is not blank/empty/null), and appends numbers in the form of [#] to the line. This command would output:

[1] notepad

[2] wordpad

findstr /B /L "[1]" -- We now take advantage of having line numbers to extract the correct command. "/B" looks for the string at the beginning of the line. "/L" is a literal search. In this example, we match line #1 which would return "notepad" as %%I

QA Automator
  • 307
  • 2
  • 12