Page 1 of 1

Copy all records but first in .txt file

Posted: 17 May 2011 12:07
by stickandrock
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

Re: Copy all records but first in .txt file

Posted: 17 May 2011 12:18
by Ed Dyreen
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

Re: Copy all records but first in .txt file

Posted: 17 May 2011 12:27
by !k
more +1 input.txt >output.txt

Re: Copy all records but first in .txt file

Posted: 17 May 2011 12:31
by Ed Dyreen
@!k
What about special characters like ^^@!รง|>>

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

Re: Copy all records but first in .txt file

Posted: 18 May 2011 11:29
by jeb
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