Skip site navigation (1)Skip section navigation (2)
Date:      Sun, 23 Jan 2000 18:47:06 -0700
From:      Charles Randall <crandall@matchlogic.com>
To:        freebsd-questions@FreeBSD.ORG
Subject:   RE: UNIX search n replace
Message-ID:  <64003B21ECCAD11185C500805F31EC0304D97797@houston.matchlogic.com>

next in thread | raw e-mail | index | archive | help
From: Greg Lehey [mailto:grog@lemis.com]
|> Charles Randall wrote:
|>> Grab a Perl manual and build something along the lines of,
|>>
|>>> perl -i.bak -pe 's/word1/word2/g;'
|
|Not quite the generic UNIX way.

Uh, whatever. These days, Perl is a standard Unix tool. 

|A better approach to the original question would be:
|
|  for i in *.c *.h; do 
|    sed <$i 's/word1/word2/g' >$i.bak; 
|    mv $i.bak $i; 
|  done

IMHO, the Perl one-liner is concise and practical.

To be perfectly clear... this one-liner is equivalent to
Greg's shell snippet,

	% perl -i.bak -pe 's/word1/word2/g;' *.[ch]

Seeing more than one way to accomplish the same task
is probably the best way to learn.

To each his own,
Charles




To Unsubscribe: send mail to majordomo@FreeBSD.org
with "unsubscribe freebsd-questions" in the body of the message




Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?64003B21ECCAD11185C500805F31EC0304D97797>