Skip site navigation (1)Skip section navigation (2)
Date:      Thu, 30 Apr 2015 21:14:10 -0400
From:      zep <zgreenfelder@gmail.com>
To:        freebsd-questions@freebsd.org
Subject:   Re: Find and replace content in 100 lines
Message-ID:  <5542D362.4060802@gmail.com>
In-Reply-To: <DM__150430194617_07750665831@mail.antennex.com>
References:  <DM__150430194617_07750665831@mail.antennex.com>

Next in thread | Previous in thread | Raw E-Mail | Index | Archive | Help


On 04/30/2015 08:58 PM, Nancy Belle wrote:
> Hi freebsd-questions
>
> I hope y'all don't mind another question, although I have a slim idea h=
ow to do it, but it would need some trial and error to get there. Probabl=
y use either sed or perl in some fashion. It's the fashion I'm unsure of.=

>
> Running fbsd-9.3
>
> This is probably easy for the script gurus on the list.
>
> 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.
>
> Hope for help, please!
>

normally I'd send jut to the poster, but in the offhand chance this can
help someone else, here are my results:

[zep@nemesis x]$ cat junk
this stuff
is
easy

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"
find this "../../../arch1/arch14"
find this "../../../arch1/arch14"
find this "../../../arch1/arch14"
find this "../../../arch1/arch14"
find this "../../../arch1/arch14"
find this "../../../arch1/arch14"
find this "../../../arch1/arch14"
[zep@nemesis x]$ cat try
perl -p -i -e
's?"../../../arch1/arch14"?"../../../../../../foo/foo2/foo3/arch1/arch14"=
?g'
[zep@nemesis x]$ perl -p -i -e
's?"../../../arch1/arch14"?"../../../../../../foo/foo2/foo3/arch1/arch14"=
?g'
junk
[zep@nemesis x]$ cat junk
this stuff
is
easy

Here's the need to fix about 100 lines in a single *.html file:
find this "../../../../../../foo/foo2/foo3/arch1/arch14"
replace with "../../../../../../foo/foo2/foo3/arch1/arch14"
find this "../../../../../../foo/foo2/foo3/arch1/arch14"
find this "../../../../../../foo/foo2/foo3/arch1/arch14"
find this "../../../../../../foo/foo2/foo3/arch1/arch14"
find this "../../../../../../foo/foo2/foo3/arch1/arch14"
find this "../../../../../../foo/foo2/foo3/arch1/arch14"
find this "../../../../../../foo/foo2/foo3/arch1/arch14"
find this "../../../../../../foo/foo2/foo3/arch1/arch14"
[zep@nemesis x]$

the "junk" file was just some text to try things with.   to make it
fully functional I'd end with something like:
cd $WEB_DIR
find . -type f (or maybe -name "*.html" if you're sure all files will be
=2Ehtml) | xargs \
   perl -p -i -e
's?"../../../arch1/arch14"?"../../../../../../foo/foo2/foo3/arch1/arch14"=
?g'

but I'd make sure to do lots of backups and try first on some junk
files/things you don't really need/are a much smaller subset of files on
a non prod machine.    I just think it'll work, I can't be sure.

oh wait.  you said a single file.   so that could work on just the on
file instead of a find.  (sorry, too lazy to erase all that, I guess) or
you could use vi on the file and do something like
: 1,$
s?"../../../arch1/arch14"?"../../../../../../foo/foo2/foo3/arch1/arch14"?=
g

--=20
public gpg key id: AE60F64C





Want to link to this message? Use this URL: <http://docs.FreeBSD.org/cgi/mid.cgi?5542D362.4060802>