Move the Contents of Text file

Discussion forum for all Windows batch related topics.

Moderator: DosItHelp

Post Reply
Message
Author
zagix
Posts: 68
Joined: 16 Oct 2013 23:19

Move the Contents of Text file

#1 Post by zagix » 05 Nov 2014 14:35

Hello,

I want to move the contents of text file and create a new file, condition to move the lines from text file, skip line 1 and last line.
Text file:
first line to skip...
33100xxxxx........
33220xxxxx.....
33340xxxxx......
33100xxxxx.....
last line to skip..

From 2nd line skip first 2 digits & next 3 digits will decide which lines will remain in the file. If its 100 it will remain there others will be moved to new file.

Result:
first line ..
33100xxxxx........
33100xxxxx.....
last line...

New file:
33220xxxxx.....
33340xxxxx......

Any Helps.

Squashman
Expert
Posts: 4479
Joined: 23 Dec 2011 13:59

Re: Move the Contents of Text file

#2 Post by Squashman » 05 Nov 2014 14:37

What do the first and last lines look like? Obfuscating data examples usually creates multiple rewrites of a script because we don't know all of the information.

zagix
Posts: 68
Joined: 16 Oct 2013 23:19

Re: Move the Contents of Text file

#3 Post by zagix » 05 Nov 2014 14:47

Hello,

Sample data.

23102014
2230002100310000101028330 000000071800002643333455446821348
2210002100210000022711 000000164200002643138993934699262
222130210021000010104 000000020600002643580679455001503
22315021002103010000029 000000021200002643339123491688650
223100210021030100000295 000000021200002642875269641084560
223150210021044006 000000005290002643788041572501935
22600021003111314 000001022977802642520322031377114
23102014 Total : 0020104008441

Aacini
Expert
Posts: 1888
Joined: 06 Dec 2011 22:15
Location: México City, México
Contact:

Re: Move the Contents of Text file

#4 Post by Aacini » 05 Nov 2014 15:51

Perhaps is this what you want?

EDIT: I changed my original answer...

Code: Select all

@echo off
setlocal EnableDelayedExpansion

del remain.txt new.txt 2>NUL
set i=0
for /F "delims=" %%a in (file.txt) do (
   set /A i+=1
   if !i! equ 1 (
      echo %%a>> remain.txt
   ) else if !i! gtr 2 (
      if "!line:~2,3!" equ "100" (
         echo !line!>> remain.txt
      ) else (
         echo !line!>> new.txt
      )
   )
   set "line=%%a"
)
echo !line!>> remain.txt

remain.txt:

Code: Select all

23102014 
2210002100210000022711 000000164200002643138993934699262
23102014 Total : 0020104008441

new.txt:

Code: Select all

2230002100310000101028330 000000071800002643333455446821348 
222130210021000010104 000000020600002643580679455001503
22315021002103010000029 000000021200002643339123491688650
223100210021030100000295 000000021200002642875269641084560
223150210021044006 000000005290002643788041572501935
22600021003111314 000001022977802642520322031377114


Antonio
Last edited by Aacini on 05 Nov 2014 16:39, edited 1 time in total.

zagix
Posts: 68
Joined: 16 Oct 2013 23:19

Re: Move the Contents of Text file

#5 Post by zagix » 05 Nov 2014 16:34

Hi,

SUPERB, EXCELLENT Aacini

Thanks.

Post Reply