Computing.Net > Forums > Programming > read file content using batch loop

Computer Problems? Computing.Net has over 1,000,000 posts about all things technology related! Over 90% answered within 24 hours! Click here to start participating now! Also, be sure to check out the New User Guide.

read file content using batch loop

Reply to Message Icon

Name: yuenli
Date: September 24, 2008 at 00:02:17 Pacific
OS: XP
CPU/Ram: Intel P4, 1Gb
Product: Dell
Comment:

Hi! I would like to read file contents from a text file and display it using a batch loop. I had try this method but it seem like did not work.

for /F "delims=" %%a in ("fileL.txt") do ( @echo %%a )



Sponsored Link
Ads by Google

Response Number 1
Name: Judago
Date: September 24, 2008 at 00:39:06 Pacific
Reply:

If your file name doesn't contain a space then simply drop the quotes from the file name like so:


for /F "delims=" %%a in (fileL.txt) do (@echo %%a)


If the file name does contain a space then you will need to use the "usebackq" option, otherwise the filename will be parsed as a text string. An example:


for /F "usebackq delims=" %%a in ("file name with spaces.txt") do (@echo %%a)

File names without spaces will also work with usebackq, even if the are contained in double quotes. See: for /? for more info.

[Edit]

Provided it contains at least 3 characters that are not spaces you could also use short (8.3) file name aliases for file names containing space(s), like so:


for /F "delims=" %%a in (filena~1.txt) do (@echo %%a)


0

Response Number 2
Name: IVO
Date: September 24, 2008 at 03:43:45 Pacific
Reply:

If you do not need to parse the text from the file, why do you not just type

type file.txt or type file.txt | more ?

Using a For /F loop is to make complex easy jobs.


0

Response Number 3
Name: ghostdog
Date: September 24, 2008 at 03:50:19 Pacific
Reply:

if that's the case , just more <file> will do.., no need for type command


0

Response Number 4
Name: Mechanix2Go
Date: September 24, 2008 at 06:52:24 Pacific
Reply:

"it seem like did not work."

not helpful


=====================================
If at first you don't succeed, you're about average.

M2


0

Response Number 5
Name: R37R0
Date: September 24, 2008 at 08:56:21 Pacific
Reply:

ECHO ON
FIND /n /I "hello word" in text1.txt >> text2.txt


No @, enable echo, if this what you mean...


0

Related Posts

See More



Response Number 6
Name: IVO
Date: September 26, 2008 at 02:36:19 Pacific
Reply:

R37R0,

for sake of correctness I have to point out what you post is absolutely wrong.

The echo command to display messages on the screen is alway enabled and the @ prefix does just suppress the echoing of the command line NOT its result.

Try to believe.


0

Sponsored Link
Ads by Google
Reply to Message Icon






Post Locked

This post is quite old and has been locked from receiving new replies. Please create a new posting instead.


Go to Programming Forum Home


Sponsored links

Ads by Google


Results for: read file content using batch loop

batch script reading file content www.computing.net/answers/programming/batch-script-reading-file-content/17385.html

Assign file contents to batch var! www.computing.net/answers/programming/assign-file-contents-to-batch-var/15181.html

VBS - How to read file contents www.computing.net/answers/programming/vbs-how-to-read-file-contents/14629.html