[Last Call] Learn how to a build a cloud-first strategyRegister Now

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 730
  • Last Modified:

look for DOS Script that help to extract data from text file

Hi There,
i am looking for Dos script that can help to extract data (from EOF until a space line marking) from a text file and put the needed data in another new file. I am not good in scripting hope can get a code to reference.

Thank you.
0
AlexKhaw
Asked:
AlexKhaw
  • 2
1 Solution
 
roadhog_NZCommented:
you could look at the windows help for "FOR"

otherwise can you be more specific? reading from EOF to a line break would mean you are reading back from the end of the file... is that what you wish to do?
0
 
AlexKhawAuthor Commented:
Yes. i would like to read from end of file and backward, until i reach a line break.
0
 
ADSaundersCommented:
Hi,
You need the unix 'tail' utility which you can get from This URL http://users.rcn.com/rprew/dos.htm which provides a download of several of the essential Unix Utilities, ported to Windows.
see http://www.cs.huji.ac.il/~bioskill/MAN/tail.html
for the unix man page.
in your DOS batch file,
tail -n 1 filename
will display the last line of the file, and
tail -n 1 filename > outputfile
will pipe the last line into a file of it's own.

Please note: I have not checked the version of tail at the URL I have included. My original link for the version I currently use is now broken. However, if it is a true port of Unix tail, the above should hold true.

Regards .. Alan


0
 
roadhog_NZCommented:
create a file called c:\test.bat
copy and paste the following code into test.bat and run
you do not need to edit the code for the first test



@echo off
rem just replace test.bat with the name of the file to read,
rem and result.txt with the name of the file to write.

set oFile=test.bat
set sWriteFile=result.txt

for /F "eol=\delims=\" %%a in (%oFile%) do set sLine=%%a
echo %sLine% > %sWriteFile%
cls
echo DATA = %sLine%
echo DATA successfully written to %sWriteFile%
pause
exit

rem this is the last line it will be written to file
0

Featured Post

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now