zim-wiki team mailing list archive
-
zim-wiki team
-
Mailing list archive
-
Message #03913
Small replace tool for UNIX ( Find and Replace)
-
To:
zim-wiki@xxxxxxxxxxxxxxxxxxx
-
From:
"Dr. Andreas Wehler" <awehler@xxxxxxx>
-
Date:
Mon, 18 Apr 2016 19:06:41 +0200
-
In-reply-to:
<CA+TmwMEHkZhKzGhbFTjydVpTcQaFxqqZ1GmzbVTd-Hv+=X1-QA@mail.gmail.com>
-
User-agent:
Mozilla/5.0 (X11; Linux x86_64; rv:38.0) Gecko/20100101 Thunderbird/38.4.0
Hi.
Under UNIX/Linux you may apply a small simple job, see attached tool
Replace.py
To replace occurences of "one two three" in any text files within
the tree /tmp to "three two one" just do:
find /tmp -name "*.txt" | Replace.py "one two three" "three two one"
and everything is done. You may also catch xml files, svg files and so on,
which would not be covered by zim itself anyway.
In this case you need python and Replace.py has to be executable,
found within your PATH.
Enjoy,
Andreas
On 04/18/2016 09:59 AM, Jaap Karssenberg wrote:
Hi Karthik,
Afraid this is not possible at the moment. However, since all content in
zim is in text files, you could use another editor with this function if
you nee dit once. If you need it often, makes sense to write a script or
plugin for this.
Regards,
Jaap
On Mon, Apr 18, 2016 at 12:35 AM Karthik Tayur <karthikstayur@xxxxxxxxx
<mailto:karthikstayur@xxxxxxxxx>> wrote:
Dear All,
Is there a way I can replace text across pages? The find and replace
tool only seems to work one page at a time (excluding sub pages).
Regards
Karthik Tayur
_______________________________________________
Mailing list: https://launchpad.net/~zim-wiki
Post to : zim-wiki@xxxxxxxxxxxxxxxxxxx
<mailto:zim-wiki@xxxxxxxxxxxxxxxxxxx>
Unsubscribe : https://launchpad.net/~zim-wiki
More help : https://help.launchpad.net/ListHelp
_______________________________________________
Mailing list: https://launchpad.net/~zim-wiki
Post to : zim-wiki@xxxxxxxxxxxxxxxxxxx
Unsubscribe : https://launchpad.net/~zim-wiki
More help : https://help.launchpad.net/ListHelp
#!/usr/bin/env python
# -*- coding: iso-8859-1 -*-
import os, re, sys
InSitu = 1; # 1: real job; 0: simulation
def file_replace(fname, s_from, s_to):
out_fname = fname + ".tmp"
out = open(out_fname, "w")
for line in open(fname):
out.write(re.sub(s_from, s_to, line))
out.close()
if InSitu:
os.rename(out_fname, fname)
else:
print "Simulated: mv %s %s" % (out_fname, fname)
def mass_replace(s_from, s_to):
for fname in sys.stdin:
fname = fname.strip()
file_replace(fname, s_from, s_to)
def main():
if len(sys.argv) != 3:
u = "Usage: find . | " + sys.argv[0] + " <string_from> <string_to>\n"
sys.stderr.write(u)
sys.exit(1)
mass_replace(sys.argv[1], sys.argv[2])
if __name__ =="__main__":
main()
References