Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

Adding Line Numbers to a text file

1 view
Skip to first unread message

Arnzie

unread,
Sep 19, 1998, 3:00:00 AM9/19/98
to
Hi, I was wondering if anybody could tell me where I could find a program
which prints line numbers.
I have a text file with the code from a program I made in Borland JBuilder,
and I want to add line numbers to the start
for easy reference. If anybody knows of such a program, could they please
email me at mka...@ballarat.starway.net.au
Any help I recieve will be much appreciated.

Thank you
Adam Arnel

--

-----------
Adam Arnel
EMAIL : mka...@ballarat.starway.net.au
WEBPAGE : http://www.ballarat.starway.net.au/~mkarnel
ICQ : 2067609

Dominic Mitchell

unread,
Sep 21, 1998, 3:00:00 AM9/21/98
to
In comp.text, Arnzie <mka...@ballarat.starway.net.au> wrote:
>Hi, I was wondering if anybody could tell me where I could find a program
>which prints line numbers.
>I have a text file with the code from a program I made in Borland JBuilder,
>and I want to add line numbers to the start
>for easy reference. If anybody knows of such a program, could they please
>email me at mka...@ballarat.starway.net.au

If your Unix has it, you can use the nl(1) utility. Otherwise, some
versions of cat(1) can do line numbering for you. Failing all that, try
using a little awk(1) script along the lines of:

$ awk '{print NR, $0}' file > newfile
--
Dom Mitchell -- Palmer & Harvey McLane -- Unix Systems Administrator
"Xerox studies suggest that most people print out electronic mail
that is longer than half a page; paper use rises by 40 percent in
offices that introduce E-mail." -- CCM

Fred Smith

unread,
Sep 21, 1998, 3:00:00 AM9/21/98
to
Dominic Mitchell (d...@phmit.demon.co.uk) wrote:

: In comp.text, Arnzie <mka...@ballarat.starway.net.au> wrote:
: >Hi, I was wondering if anybody could tell me where I could find a program
: >which prints line numbers.
: >I have a text file with the code from a program I made in Borland JBuilder,
: >and I want to add line numbers to the start
: >for easy reference. If anybody knows of such a program, could they please
: >email me at mka...@ballarat.starway.net.au

: If your Unix has it, you can use the nl(1) utility. Otherwise, some
: versions of cat(1) can do line numbering for you. Failing all that, try
: using a little awk(1) script along the lines of:

Or if you have a grep utility:

grep -n '^.*$' infile > outfile

Fred
--
---- Fred Smith -- fre...@fcshome.stoneham.ma.us -----------------------------
"For the word of God is living and active. Sharper than any double-edged
sword, it penetrates even to dividing soul and spirit, joints and marrow;
it judges the thoughts and attitudes of the heart."
---------------------------- Hebrews 4:12 (niv) ------------------------------

Moshe Zadka

unread,
Sep 22, 1998, 3:00:00 AM9/22/98
to
On 21 Sep 1998, Gabor wrote:

> In comp.editors, Arnzie <mka...@ballarat.starway.net.au> wrote :
> # Hi, I was wondering if anybody could tell me where I could find a program
> # which prints line numbers.
> # I have a text file with the code from a program I made in Borland JBuilder,
> # and I want to add line numbers to the start
> # for easy reference. If anybody knows of such a program, could they please
> # email me at mka...@ballarat.starway.net.au
> # Any help I recieve will be much appreciated.
> #
> # Thank you
> # Adam Arnel
>
> cat -n <file>

Or, with perl
----- Cut here -----
#!/usr/bin/perl -w
use strict;

my $i=1;
while(<>) {
print $i++, " ", $_;
}
----- Cut here -----
Or, in C
----- Cut here -----
#include <stdio.h>

int main(int argc, char **argv)
{
int i=1;
int c;

printf("%10d ", i++);
while((c=getc(stdin))!=EOF) {
putc(c, stdout);
if(c=='\n') {
printf("%10d ", i++);
}
}

}
----- Cut here --------
Or with awk
----- Cut here --------
#!/usr/bin/awk -f
{print NR, $0}
----- Cut here --------

Which do you prefer?


--
Moshe Zadka <mos...@math.huji.ac.il> | (\_/)
What's Yellow and Complete?A Bananach Space|( =(^Y^)=
Being smart means being able to count to 20| \_(m___m)
without taking off your shoes - Micky Mouse|(originally by jgs)


William Park

unread,
Sep 22, 1998, 3:00:00 AM9/22/98
to
Arnzie (mka...@ballarat.starway.net.au) wrote:
: Hi, I was wondering if anybody could tell me where I could find a program
: which prints line numbers.
: I have a text file with the code from a program I made in Borland JBuilder,
: and I want to add line numbers to the start
: for easy reference. If anybody knows of such a program, could they please
: email me at mka...@ballarat.starway.net.au
: Any help I recieve will be much appreciated.

: Thank you
: Adam Arnel

'cat -n' will number each line.
--

Al Aab

unread,
Sep 23, 1998, 3:00:00 AM9/23/98
to
1- cat -n
2- ln
3- DOS norton utilities lp (line printer w options)
4- sed onliner by al aab (more flixible, if u know sed)
see oneliners in:

~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
SED RESOURCES
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

to master regular expressions
to master sed
join my seders informal email list :
af...@torfree.net
----

sed web pages


"sed one liners" by Eric Pement
"Doing It with sed" by sed stud Carlos
http://seders.icheme.org/ seders grab bag (seders official web page)
http://www.dbnet.ece.ntua.gr/~george/#seders seder, engineer, Dr2b Yiorgos


THE SED FAQ

latest version of the sed FAQ is usually at:
http://seders.icheme.org/tutorials/sed_faq.txt
http://www.dbnet.ece.ntua.gr/~george/sed/sedfaq.html
http://www.ptug.org/sed/sedfaq.html
http://www.cornerstonemag.com/sed/sedfaq.html

----

http://www.math.fu-berlin.de/~guckes/sed/ seder Herr Guckes
http://www.math.fu-berlin.de/~leitner/sed/ Herr Leitner
http://www.ptug.org/sed/custom_sed.html supersed writer, seder Simon Taylor
http://www.cis.nctu.edu.tw/~gis84806/sed exotic scripts.seder Yao-Jen Chang

sed/regular expressions tutorials/refs

1- http://www.dordt.edu:457/OSUserG/BOOKCHAPTER-14.html
Chapter 14, Manipulating text with sed
2- "Doing It with sed" by sed stud Carlos (see http's above)

3- SunOS Manual Pages
http://www.intac.com/man/sunos/sed.1v.html
http://cmgm.stanford.edu/man2html/sed.1v.html

4- u-sedit2. has nice sed docs.
http://wuarchive.wustl.edu/systems/ibmpc/garbo.uwasa.fi/editor/u-sedit2.zip

5- dc UNIX stack-calculator, in sed, by sed stud GREG UBBEN
http://www.dbnet.ece.ntua.gr/~george/sed/dc.sed.html

6- sierpinski gasket/triangle, in sed, by sed stud KEN PIZZINI
posted by Al Aab, in July 1998 to
alt.comp.editors.batch & comp.unix.shell
search dejanews

----


some sed implementaions


"official" release of GNU sed-3.01 is finally available from:
ftp://ftp.gnu.org/pub/gnu/sed-3.01.tar.gz

sedmod.zip very extended/awkish DOS sed
ftp://ftp.adam.anet.cz/pub/cdrom3/fileutil/sedmod.zip
http://www.ptug.org/sed/SEDMOD10.ZIP

MKS Toolkit, windows 32 http://www.mks.com

ftp://uiarchive.uiuc.edu/pub/systems/pc/simtelnet/win95/util/
ud32_v43.zip B 3381699 980512 UnixDos: Full Unix set: 65 progs +28 new
utils

ftp://uiarchive.uiuc.edu/pub/systems/pc/simtelnet/win3/util/
ud16_v42.zip B 4767550 980313 UnixDos: Full Unix set. 64 progs +28 new
utils


----
my favourite DOS/UNIX sed :

ftp://uiarchive.uiuc.edu/pub/systems/pc/simtelnet/msdos/txtutl/sed15.zip
ftp://uiarchive.uiuc.edu/pub/systems/pc/simtelnet/msdos/txtutl/sed15x.zip

Directory: /pub/systems/pc/simtelnet/msdos/txtutl/
Filename Type Length Date Description
sed15.zip B 62082 910930 Unix-compatible streaming editor v1.5 TC src
sed15x.zip B 20300 910930 Unix-compatible streaming editor v1.5 EXE/docs

sed15.zip has C source, compilable for UNIX.

sed15.exe compiled with mingw32 for 32bit environments at:
http://www.dbnet.ece.ntua.gr/~george/sed/sed15.exe
----
sed/batch/text newsgroup:
alt.comp.editors.batch
if your newsfeed does not carry it, search dejanews.
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~


William Park (cv...@torfree.net) wrote:

: : Thank you
: : Adam Arnel

--
=-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-
al aab, seders moderator sed u soon
it is not zat we do not see the s o l u t i o n
-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-+

Eric Pement

unread,
Sep 23, 1998, 3:00:00 AM9/23/98
to
On Sat, 19 Sep 1998 22:15:25 +1000, "Arnzie"
<mka...@ballarat.starway.net.au> wrote:

>Hi, I was wondering if anybody could tell me where I could find a program
>which prints line numbers.

Download this file (about 830k) of the Unix text utilities:
ftp://ftp.simtel.net/pub/simtelnet/gnu/djgpp/v2gnu/txt122b.zip

These are the standard suite of GNU text utilities ported to
MS-DOS. You'll find that nl.exe is a flexible, powerful program for
numbering lines -- that's all it's intended to do. You can also number
lines with "cat.exe -n filename", but nl has more options.

Eric Pement

--
Eric Pement <epe...@jpusa.chi.il.us>
senior editor, Cornerstone magazine
http://www.cornerstonemag.com
939 W. Wilson Ave., Chicago, IL 60640-5706
tel: 773/561-2450, 1-(ext.)2084 fax: 773/989-2076

0 new messages