Find and replace content in 100 lines
Alex Merritt
merritt.alex at gmail.com
Fri May 1 20:20:29 UTC 2015
Hello Nancy,
On Thu, Apr 30, 2015 at 8:58 PM, Nancy Belle <belle at antennex.com> wrote:
>
> Here's the need to fix about 100 lines in a single *.html file:
> find this "../../../arch1/arch14"
> replace with "../../../../../../foo/foo2/foo3/arch1/arch14"
>
> The quotes are there too.
>
You want sed with the search/replace feature, generally:
sed s/regular expression/replacement/flags
like so
sed -i .orig
's:"../../../arch1/arch14":"../../../../../../foo/foo2/foo3/arch1/arch14":g'
input.html
Those single quotes are important, to prevent the shell from doing any
interpretation within anything enclosed between them (e.g. environment
variables, if there were any, and from removing the double quotes). The
single quotes aren't important to sed.
The colon (a forward slash in the example) is the delimiter character, and
can be any character you like (except backslash and newline). Pick one
which does not appear in your strings you are searching and replacing.
-i tells sed to edit the file directly, first making a copy with the given
extension as the backup.
Hope this helps,
Alex
More information about the freebsd-questions
mailing list