You don't give quite enough of a spec to choose the best tool but any of "gawk", "sed", "perl" would do it.
Decompose the problem into smaller sub-problems & make a tool which will meet each sub-objective - then string them all together in a shell script. Thus using "find" with the appropriate args might well find all of the files you need to act on and pipe their names into "xargs" or a script of your own. My preference would probably be "gawk" for the actual search & replace but I couldn't be quite sure until I'd got the detailed spec and done half an hour's experiments.
I'm assuming that efficiency of execution isn't as important as getting the job done but even if it is to become a "production" job, it's probably still woth prototyping it as a little bunch of scripts which you can rewrite in your language of choice later if needed.
You've certainly got exactly the right environment for this kind of ad hoc text processing in *N*X - there are loads more text hacking tools than those I've mentioned.
Try http://www.oreilly.com/catalog/awkprog2/ for help on awk/gawk.
Regards
Andrew Wallis Fox Cottage Fox Hill St Cross South Elmham HARLESTON IP20 0NX UK
phone: +44 (0) 1986 782283 mobile: +44 (0) 7860 217025 SMS via email: mailto:+447860217025@mmail.co.uk
-----Original Message----- From: Paul paul.corner@tesco.net To: ALUG main@lists.alug.org.uk Date: Mon, 13 May 2002 23:09:53 +0100 Subject: [Alug] Help with search & replace
Hi Folks
I am in need of some help - I have a large number of small text files that need to be scanned and one specific phrase replaced at each occurrence excluding the first line (which may or may not contain the offending words). I suspect that something like perl may be the most suitable tool for the task in hand. But I know nothing about it.... Just to add to the problem, the files are scattered across multiple directories and the key phrase may span two lines.
Regards, Paul.
--__--__--
main@lists.alug.org.uk http://www.anglian.lug.org.uk/ http://lists.alug.org.uk/mailman/listinfo/main
End of main Digest