Automatically line numbering scripts for posting. 
Author Message
 Automatically line numbering scripts for posting.

You probably seen other people post sample scripts that were line numbered.
This allowed for the individual commands of the script to be referenced by
their line number. But it also clearly showed if any of the lines had been
wrapped by the mail/news reader and should be joined back as one.

I wrote the first version of the below script a while back. Recently I added
the ability to use it as a filter. I thought that others might find it
useful and have decided to make the script available as freeware. And
therefore, to make it more user friendly, I've added the Help Message
(Instructions) that pops up if you just double click on it (assuming you use
wscript.exe by default).  If not, see below for what the help message says.

For those of you that like a challenge, lets see who can write a script that
will remove the line numbers taking into account that some lines may be
wrapped.

--------------------------------------------------
Help Message/Instructions
--------------------------------------------------

To Use as a filter. . .

  cscript "Create Line-Numbered List.vbs" < InFile > OutFile
  anyconsolecommand | cscript "Create Line-Numbered List.vbs" > OutFile
  cscript "Create Line-Numbered List.vbs" > OutFile

  In the third example, output from the keyboard will saved to the specified
  OutFile! Use <Ctrl-Z> terminate (close) redirection.

To process one or more files. . .

  wscript "Create Line-Numbered List.vbs" filename1 [filename2...]

  Each file will have a line-numbered copy if itself created with the same
  filename and a LST extension. No wildcards are allowed in the filenames.

As a "Send To" Item (My Favorite!). . .

  Create a shortcut to this script in the SendTo folder, usually
  C:\Windows\SendTo.

--------------------------------------------------

[--- Begin: C:\WINDOWS\WSH\Create Line-Numbered List.vbs ---]

001. ' Windows Script Host - VBScript
002.
'---------------------------------------------------------------------------
-----
003. '       Name: Create Line-Numbered List
004. '         By: Harvey Colwell
005. '    Version: 1.2
006. '  CopyRight: (c) Oct 2000, All Rights Reserved!
007. '   Freeware: No Warrantees or Guarantees
008.
'***************************************************************************
*****
009.
010.   Option Explicit
011.
012.   Dim oWS, oFS
013.
014.   Set oWS = WScript.CreateObject("WScript.Shell")
015.   Set oFS = WScript.CreateObject("Scripting.FileSystemObject")
016.
017. '----------
018. ' Script Setup
019. '----------
020.   Dim oInStream, oOutStream, sInFile, sOutFile, nTotalLines, sArg
021.
022. '----------
023. ' Process File(s)
024. '----------
025.   If Wscript.Arguments.Count = 0 Then
026.     If InStr(LCase(WScript.FullName), "cscript.exe") <> 0 Then
027.       sInFile = "StdIn"
028.       sOutFile = "StdOut"
029.       Set oInStream = WScript.StdIn
030.       Set oOutStream = WScript.StdOut
031.         Call ProcessFile()
032.     Else
033.       Call HelpMsg()
034.     End If
035.   Else
036.     For sArg = 0 To Wscript.Arguments.Count -1
037.       sInFile = Wscript.Arguments(sArg)
038.       If IsFile(sInFile) Then
039.         sOutFile = Left(sInFile, InStrRev(sInFile, ".") - 1) & ".lst"
040.         Set oOutStream = oFS.OpenTextFile(sOutFile, 2, True, 0)
041.         Set oInStream = oFS.OpenTextFile(sInFile, 1)
042.           Call ProcessFile()
043.         oWS.Run "NotePad.exe " & sOutFile
044.       Else
045.         Wscript.Echo "File Not Found: " & sInFile, , "Error"
046.       End If
047.     Next
048.   End If
049.
050.   Call CleanUp(0)
051.
052.
'---------------------------------------------------------------------------
-----
053. ' Subroutines
054.
'***************************************************************************
*****
055.
056. '---------------------
057.   Sub CleanUp(exitCode)
058.     Set oInStream = Nothing
059.     Set oOutStream = Nothing
060.     Set oWS = Nothing
061.     Set oWS = Nothing
062.     WScript.Quit(exitCode)
063.   End Sub
064.
065. '---------------------
066.   Sub ProcessFile()
067.     oOutStream.WriteLine vbCrlf & "[--- Begin: " & sInFile & " ---]" &
vbCrlf
068.       nTotalLines = AddLineNum()
069.     oOutStream.WriteLine vbCrlf & "[--- End: " & sInFile & " ---]" &
vbCrlf
070.   End Sub
071.
072. '---------------------
073.   Sub HelpMsg()
074.     MsgBox "To Use as a filter. . ." & vbCrlf & vbCrlf & _
075.       "  cscript ""Create Line-Numbered List.vbs"" < InFile > OutFile"
& vbCrlf & _
076.       "  any_console_command | cscript ""Create Line-Numbered
List.vbs"" > OutFile" & vbCrlf & _
077.       "  cscript ""Create Line-Numbered List.vbs"" > OutFile" & vbCrlf
& vbCrlf & _
078.       "  In the third example, output from the keyboard will saved to
the specified"  & vbCrlf & _
079.       "  OutFile! Use <Ctrl-Z> terminate (close) redirection." & vbCrlf
& vbCrlf & _
080.       "To process one or more files. . ." & vbCrlf & vbCrlf & _
081.       "  wscript ""Create Line-Numbered List.vbs"" filename1
[filename2...]" & vbCrlf & vbCrlf & _
082.       "  Each file will have a line-numbered copy if itself created
with the same" & vbCrlf & _
083.       "  filename and a LST extension. No wildcards are allowed in the
filenames." & vbCrlf & vbCrlf & _
084.       "As a ""Send To"" Item (My Favorite!). . ." & vbCrlf & vbCrlf & _
085.       "  Create a shortcut to this script in the SendTo folder,
usually" & vbCrlf & _
086.       "  C:\Windows\SendTo.", , "Instructions"
087.     Call CleanUp(1)
088.   End Sub
089.
090.
'---------------------------------------------------------------------------
-----
091. ' Functions
092.
'***************************************************************************
*****
093.
094. '---------------------
095.   Function AddLineNum()
096.     Dim nLine, sLine, nCount
097.     nCount = 0
098.     Do Until oInStream.AtEndOfStream
099.       nLine = oInStream.Line
100.       sLine = oInStream.ReadLine
101.       oOutStream.WriteLine Pad(nLine, 3, 0) & ". " & sLine
102.       nCount = nCount + 1
103.     Loop
104.     AddLineNum = nCount
105. End Function
106.
107. '---------------------
108.   Function Pad(Value, Width, Char)
109.     Pad = Right(String(Width, CStr(Char)) & CStr(Value), Width)
110.   End Function
111.
112. '---------------------
113.   Function IsFile (fName)
114.     If oFS.FileExists(fName) Then IsFile = True Else IsFile = False
115.   End Function
116.
117. '
****************************************************************************
****

[--- End: C:\WINDOWS\WSH\Create Line-Numbered List.vbs ---]



Mon, 19 May 2003 03:00:00 GMT  
 Automatically line numbering scripts for posting.

Quote:
> You probably seen other people post sample scripts that were line
numbered.
> This allowed for the individual commands of the script to be
referenced by
> their line number. But it also clearly showed if any of the lines had
been
> wrapped by the mail/news reader and should be joined back as one.

<snip>
> For those of you that like a challenge, lets see who can write a
script that
> will remove the line numbers taking into account that some lines may
be
> wrapped.

<snip>

> To Use as a filter. . .

>   cscript "Create Line-Numbered List.vbs" < InFile > OutFile
>   anyconsolecommand | cscript "Create Line-Numbered List.vbs" >
OutFile
>   cscript "Create Line-Numbered List.vbs" > OutFile

How about:

type a.vbs | cscript linenum.vbs | more

--
Robert Bradley

I am not a mindreader, so I don't know everything.



Sat, 24 May 2003 03:00:00 GMT  
 Automatically line numbering scripts for posting.
You can use the batch file below too.
Just drag and drop a (script) file on Line-Numbering.bat.
The line numbered file is save with a NUM (TXT is probably more easy) extension that is edited with Notepad for convenience.


find /N /V "$$$$$$$$" %1|find /V "%1"> %1.num
notepad %1.num
cls
::---8<---Line-Numbering.bat---Cut Here---

Result Sample
--------------

[1]t="Hello"
[2]u= " "
[3]v="World"
[4]w="!"
[5]wscript.echo t & u & v & u & w
... to be continued ...

Regards,

Jean - JMST
Belgium



Wed, 28 May 2003 09:04:12 GMT  
 
 [ 3 post ] 

 Relevant Pages 

1. Automatically line numbering scripts for posting.

2. Post Script Page Numbers

3. Script editor with line numbers

4. Automatically posting values to another page

5. automatically post question and send email

6. send form with POST automatically

7. Number of postings to comp.lang.* newsgroups.

8. Line Break - 2nd Post

9. post data in ASP / line breaks for email

10. line after line in a script

11. Scripting command line applications & Command Line Prompting

12. number of lines of the document

 

 
Powered by phpBB® Forum Software