Computing.Net > Forums > Programming > batch script reading file content

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.

batch script reading file content

Reply to Message Icon

Name: starp
Date: December 14, 2008 at 13:00:22 Pacific
OS: AMD
CPU/Ram: Core 2 dual
Product: Compaq / DFDSFDS
Comment:

Hi

I need a batch script which will read file content till a certain character, rename file with the original file name_content read.

Thanks
Starp



Sponsored Link
Ads by Google

Response Number 1
Name: Judago
Date: December 14, 2008 at 17:25:05 Pacific
Reply:

What type of file is it? If it contains any binary that isn't plain text then it won't work with plain batch.

Also what os is this batch intended for?


0

Response Number 2
Name: starp
Date: December 14, 2008 at 20:47:44 Pacific
Reply:

hi

Os is windows 2000 professional
text is plain text

thanks


0

Response Number 3
Name: Judago
Date: December 14, 2008 at 21:51:08 Pacific
Reply:

This may do it, though it has no regard for blank lines and will leave them out. Where the script calls for x substitute your character("!line:x=!" and if "!line:~0,1!"=="x"). I have also prefixed the ren and move commands with echo for testing purposes, I suggest you leave them their until you are sure it does what you want.


@ECHO OFF
setlocal
for /f "usebackq delims=" %%a in ("your text file.txt") do (
set line="%%a"
SETLOCAL ENABLEDELAYEDEXPANSION
set line=!line:~1,-1!
if "!line:x= !"=="!line!" (
echo !line!>>newtextfile
) else (
call :partline
goto finish
)
SETLOCAL DISABLEDELAYEDEXPANSION
)
goto :finish

:partline
if not defined line if defined pl (echo !pl!>>newtextfile&&goto :eof) else goto :eof
if "!line:~0,1!"=="x" echo:!pl!>>newtextfile&&goto :eof
set pl=!pl!!line:~0,1!
set line=!line:~1!
goto partline
:finish
ren "your text file.txt" "your text file.txt name_content read"
move newtextfile "your text file.txt name_content read"
pause



0

Sponsored Link
Ads by Google
Reply to Message Icon

Related Posts

See More







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: batch script reading file content

read file content using batch loop www.computing.net/answers/programming/read-file-content-using-batch-loop/17010.html

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

Batch script for file copy www.computing.net/answers/programming/batch-script-for-file-copy/14874.html