Date: 26 Jan 2005 10:54:30 -0500 From: Lowell Gilbert <freebsd-questions-local@be-well.ilk.org> To: Anthony Atkielski <atkielski.anthony@wanadoo.fr> Subject: Re: One-line global string replace in all files with sed (or awk?) Message-ID: <44r7k82nk9.fsf@be-well.ilk.org> In-Reply-To: <1878149195.20050126164325@wanadoo.fr> References: <1878149195.20050126164325@wanadoo.fr>
next in thread | previous in thread | raw e-mail | index | archive | help
Anthony Atkielski <atkielski.anthony@wanadoo.fr> writes: > A few years ago, I'm sure I came across a one-line way of replacing > every occurence of one string with another in an entire directory of > files (potentially including all subdirectories as well). I think it > used sed or awk. Now I can't find it. The examples on the Web are all > multiline scripts or programs, but I'm sure I saw a way to do it all on > just one line. > > Can anyone tell me how to do this? You should be able to figure this out pretty quickly on your own from the manual, but I'll do your homework for you... find . -type f -exec sed -i "" -e "s/e/E/g" {} \; [changes every lower-case e to upper-case in all regular files in this directory and all directories "below" it] [There are several other ways to do it, too, in about the same amount of typing. In particular, using xargs(1) instead of -exec could make it run faster if you have large numbers of files.]
Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?44r7k82nk9.fsf>