Kevin Carpenter
Kevin Carpenter

Reputation: 11

Windows FOR /F - Echo each line in file - Spaces in line - FAIL

I have a simple text file and would like to echo each line of the file. This fails if the line has SPACES in it.

Here is the contents of the text file - " t.t " Indented for clarity.

  1
  2
  3
  4
  5
  a.a
  This Had Spaces

Here's the failing code :

FOR /F %G IN (t.t) DO (@echo %G)
1
2
3
4
5
a.a
This

FOR /F "usebackq" %G IN (t.t) DO (@echo %G)
1
2
3
4
5
a.a
This

Notes : This is not a batch file - but rather run directly at the WinXP command prompt - hence the % rather than %%

Upvotes: 1

Views: 1305

Answers (1)

MC ND
MC ND

Reputation: 70933

FOR /F "usebackq delims=" %G IN ("t.t") DO (@echo %G)

By default for /f will tokenize the input records using spaces and tabs as delimiters. If you use an empty list of characters in the delims clause, this behaviour is disabled.

Upvotes: 2

Related Questions