moving one line from a txt to another txt.

January 27, 2010 at 05:57:35
Specs: Windows
Dear all..

i want to create a for-loop
I want to create a MS-DOS batch script that takes the first line
of a txt file and moves it to another text file.
and then it should take the 2. line from file 1
and move it (and overwrite 1st line) in file 2.
and then keep doing so until the 1st file is empty.

can anybody help me?


See More: moving one line from a txt to another txt.

Report •

#1
January 27, 2010 at 06:15:04
Do you really need the loop ? You could just write the last line of file 1, to file 2 ... Or do you mean that EACH line of file 1 should be written to a separate new file ?

ps, in english "1." is written as "first", or "1st" ... I don't think any other language than German uses the number-dot notation


Report •

#2
January 27, 2010 at 06:36:53
You start by saying what exact OS you're using.

And, as indicated in #1, do some careful thinking about what needs to be done.


=====================================
Helping others achieve escape felicity

M2


Report •

#3
January 27, 2010 at 07:12:45
Just a question, but does anybody know why there is not a specific subforum for each of the programming languages ? I mean, there is a difference between DOS 2.0 and the command-line-whatever-we-will-call-it-this-time-command-line-interface-hey-I-am-not-DOS in Windows 7 ... but,

you know, there are groups of languages:
- DOS/Windows/related
- unix bash, bourne,
- java
- c/c++
- VB
- some more, which each are distintcly different from the above

You know, it could prevent each thread to start with : and what language do you want it in ? Having said this, I see "MS-DOS" in the opening post ... ;)


Report •

Related Solutions

#4
January 27, 2010 at 07:22:37
My guess as to why no separate forums for the individual alnguages is that there's not enough traffic to jusitfy it.


=====================================
Helping others achieve escape felicity

M2


Report •

#5
January 27, 2010 at 13:37:34
i kindof like it this way (mixed languages) because many times a problem can be solved by using alternative languages or a combination of languages. So it seems self-defeating to try and catagorize them into forums. also, this way i get exposed to other languages methods and syntax etc.

@op: it can be done in generic windows environment, i think, if filesize is under about 38K AND if fc sets the errorlevel
(some older versions don't seem to)

@echo off>empty.fil
copy /y empty.fil topline
echo x>>topline

echo #tmain>ed2
echo 1d>>ed2
echo 2,#d>>ed2
echo e>>ed2

echo 1d>ed1
echo e>>ed1
edlin empty.fil<ed1

:aa
edlin topline < ed2 >nul
edlin main < ed1 >nul
:: type file and pause for testing etc.
echo sourcefile:
type main
pause
echo last topline:
type topline
pause
\comands\fc main empty.fil>nul
if errorlevel 1 goto :aa
:xx
echo done.


Report •

#6
January 28, 2010 at 01:19:29
im so sorry if i was unclear.

@ response 1: the reason why i wanted it to be at for loop is
because i wanted it to do some other stuff as well, everytime it
had moved a line ;)

@ response 2: it is suppose to run on a windows 2008 server.


Report •

#7
January 28, 2010 at 02:28:23
Weiss (I'll not call you Uber), I expected that answer indeed, but I needed to know ...

Does Nbrane's code work ?


Report •

#8
January 28, 2010 at 02:49:34
Dear nbrane & tvc.

unfortunately i couldnt get the script working.

it nulls out both files


Report •

Ask Question