MACSCRPT Archives

September 2009

MACSCRPT@LISTSERV.DARTMOUTH.EDU

Options: Use Monospaced Font
Show Text Part by Default
Show All Mail Headers

Message: [<< First] [< Prev] [Next >] [Last >>]
Topic: [<< First] [< Prev] [Next >] [Last >>]
Author: [<< First] [< Prev] [Next >] [Last >>]

Print Reply
Subject:
From:
Sander Tekelenburg <[log in to unmask]>
Reply To:
Macintosh Scripting Systems <[log in to unmask]>
Date:
Fri, 18 Sep 2009 02:35:42 +0200
Content-Type:
text/plain
Parts/Attachments:
text/plain (28 lines)
At 13:13 -0700 UTC, on 2009-09-17, [log in to unmask] wrote:

> I'm trying to find every line in a 2800-line pipe delimited file that
> contains: |(TRAV)|

[...]

> The version below returns every line of the file.

I get your result when the input file contains Mac linebreaks[*]. Change the
input file's linebreaks to unix linebreaks[*], and the below works fine:

set input to quoted form of POSIX path of (choose file)
do shell script "grep '|(TRAV)|' " & input

The clue was given by using grep's -n flag, which prints line numbers for
every line found. With the Mac line endings in the input file, grep printed
only a single line number, indicating that it considered the file to contain
a single line. And since that single line does contain the needle, it was
given as the result.

[*] With "Mac linebreaks" and "unix linebreaks" I'm using BBEdit/TextWrangler
terminology.


-- 
Sander Tekelenburg, <http://www.euronet.nl/~tekelenb/>

ATOM RSS1 RSS2