Re: Line Numbers in ASCII File

Subject: Re: Line Numbers in ASCII File
From: Sandy Harris <sandy -at- storm -dot- ca>
To: "TECHWR-L" <techwr-l -at- lists -dot- raycomm -dot- com>
Date: Thu, 07 Feb 2002 11:46:13 -0500

Steve Goldberg wrote:
> We have a huge ASCII text file against which we would like to do
> searches to find matching strings in the text. Once we match a
> particular text string we would like to be able to determine on what
> line number or page number that string is located.
> Does anyone know of a way to do this? In Word, of course, it's simple,
> but that formatting is lost when the file is saved as plain text.

On Unix, or with Unix tools installed on a Win box:

that's just grep -n. This has been a standard tool since at least the
late 70s.

It also gives the ability to match more complex patterns. For example.

grep -n '1\-8[08][08]\-[0-9]+'

is my (first guess, without looking at the manual, and untested, so quite
likely wrong) attempt to get all lines with North American toll-free phone
numbers. It matches any string with these pieces, in order:
"0" or "8"
"0" or "8"
at least one digit
With some practice and a bit of mucking about, you can do quite a
lot with this "regular expression" search facility.

Collect Royalties, Not Rejection Letters! Tell us your rejection story when you
submit your manuscript to iUniverse Nov. 6 -Dec. 15 and get five free copies of
your book. What are you waiting for?

Have you looked at the new content on TECHWR-L lately?
See and check it out.

You are currently subscribed to techwr-l as: archive -at- raycomm -dot- com
To unsubscribe send a blank email to leave-techwr-l-obscured -at- lists -dot- raycomm -dot- com
Send administrative questions to ejray -at- raycomm -dot- com -dot- Visit for more resources and info.

Line Numbers in ASCII File: From: Steve Goldberg

Previous by Author: Re: upgrade from 98 to XP
Next by Author: Re: QUERY: spelling, e.g. or eg
Previous by Thread: Line Numbers in ASCII File
Next by Thread: RE: Line Numbers in ASCII File

What this post helpful? Share it with friends and colleagues:

Sponsored Ads