Copy all records but first in .txt file

Discussion forum for all Windows batch related topics.

Moderator: DosItHelp

Post Reply
Message
Author
stickandrock
Posts: 4
Joined: 18 Dec 2009 07:59

Copy all records but first in .txt file

#1 Post by stickandrock » 17 May 2011 12:07

I have a txt file that I want to copy and in the resulting output file I do not want to include the first record of the original file.

Much Appreciated,
Don

Ed Dyreen
Expert
Posts: 1569
Joined: 16 May 2011 08:21
Location: Flanders(Belgium)
Contact:

Re: Copy all records but first in .txt file

#2 Post by Ed Dyreen » 17 May 2011 12:18

I don't have a batch solution, &if someone has one that processes special characters without a glitch I'd like to know aswell.
In the meantime this is what I use to overcome this problem.
I know simple BATCH solutions ofcourse but then I always run into problems with special characters....

MinStrCFile.VBS

Code: Select all

If WScript.Arguments.Count <> 3 Then
  Wscript.Echo "Usage: CScript.exe commandLine.vbs <SourceFile> <DestFile> <SkipLinesCOUNT>"
End If
'''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''4''
Dim shell,oFSO,oFilein,SourceFile,DestFile,COUNT,SkipLinesCOUNT

set shell = createobject("wscript.shell")
Set oFSO = CreateObject("Scripting.FileSystemObject")

' IMode Values
Const ForAppending = 8,   ForReading = 1, ForWriting = 2
Const ReadTheFile = False, CreateTheFile = True

' Format Values
Const ASCII = 0, UniCode = -1, Default = -2
''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''21''
SourceFile   = WScript.Arguments(0)
DestFile   = WScript.Arguments(1)
SkipLinesCOUNT   = WScript.Arguments(2)

Set oFilein    = oFSO.OpenTextFile(SourceFile, ForReading, ReadTheFile)
Set oFilemin    = oFSO.OpenTextFile(DestFile, ForWriting, CreateTheFile, Default)

on error resume next
Do while not oFilein.AtEndOfStream
  WriteLine = oFilein.ReadLine
  If COUNT < SkipLinesCOUNT then
    COUNT = COUNT + 1
  Else
    oFilemin.Write WriteLine & VBNewLine
  End If
Loop

oFilemin.close
oFilein.close

!k
Expert
Posts: 378
Joined: 17 Oct 2009 08:30
Location: Russia

Re: Copy all records but first in .txt file

#3 Post by !k » 17 May 2011 12:27

more +1 input.txt >output.txt

Ed Dyreen
Expert
Posts: 1569
Joined: 16 May 2011 08:21
Location: Flanders(Belgium)
Contact:

Re: Copy all records but first in .txt file

#4 Post by Ed Dyreen » 17 May 2011 12:31

@!k
What about special characters like ^^@!ç|>>

I suppose that is not a problem with more :?:

jeb
Expert
Posts: 1055
Joined: 30 Aug 2007 08:05
Location: Germany, Bochum

Re: Copy all records but first in .txt file

#5 Post by jeb » 18 May 2011 11:29

Ed Dyreen wrote:I don't have a batch solution, &if someone has one that processes special characters without a glitch I'd like to know aswell.


It is possible :)

Code: Select all

setlocal DisableDelayedExpansion
for /f "delims=" %%A in ('"findstr /n ^^ myFile.txt"') do (
   set "line=%%A"
   setlocal EnableDelayedExpansion

   set "line=!line:*:=!"
   (echo(!line!)
   endlocal
)


This works with all special characters, even with empty lines (therefore I use the findstr /n to enumerate the lines)

jeb

Post Reply