Chop and replace method??
Jon Radel
jon at radel.com
Sat Apr 4 22:51:55 UTC 2015
On 4/4/15 5:58 PM, Nancy Belle wrote:
>>>> sed -i .bak 's/href=\"..\/..\/..\/archival\/archive13\//href=\"/' *.html
>>>>
> Hi Jon Radel
>
> Oops! I forgot to mention that the *.html files are in different directories and sub-directories. What do I need to add if possible to make sed work with that situation?
So many options. If you're using sh you could always do the quick and
dirty:
for i in `find . -name '*html'` ; do sed -i .bak
's/href=\"..\/..\/..\/archival\/archive13\//href=\"/' $i ; done
while in the directory under which all files you want to change reside.
Polytropon is correct that his version
sed -i .bak 's|href="../../../archival/archive13/|href="|g' *.html
is more readable, and the trailing "g" is important if you have more
than one href you need to change per line.
to combine things a bit, my current favorite for your problem as I
currently conceive it is
find . -name '*.html' -execdir sed -i .bak
's|href="../../../archival/archive13/|href="|g' {} \;
when run from the directory under which all the files live, or you could
change "find ." to "find <directory>".
List added back in.
--Jon Radel
jon at radel.com
-------------- next part --------------
A non-text attachment was scrubbed...
Name: smime.p7s
Type: application/pkcs7-signature
Size: 3870 bytes
Desc: S/MIME Cryptographic Signature
URL: <http://lists.freebsd.org/pipermail/freebsd-questions/attachments/20150404/0e0ff2c1/attachment.bin>
More information about the freebsd-questions
mailing list