Ask confirmation for every change performed by Sed script
ProgrammingThis forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.
Notices
Welcome to LinuxQuestions.org, a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
If you have any problems with the registration process or your account login, please contact us. If you need to reset your password, click here.
Having a problem logging in? Please visit this page to clear all LQ-related cookies.
Get a virtual cloud desktop with the Linux distro that you want in less than five minutes with Shells! With over 10 pre-installed distros to choose from, the worry-free installation life is here! Whether you are a digital nomad or just looking for flexibility, Shells can put your Linux machine on the device that you want to use.
Exclusive for LQ members, get up to 45% off per month. Click here for more info.
Ask confirmation for every change performed by Sed script
Dear Linux users,
I have a sed script that I use to automatically correct many of my most common writing mistakes in LaTeX documents. This sed script contains more than thousand lines in the form:
(...)
s/betwenn/between/g;
s/bilatteral/bilateral/g;
s/bussiness/business/g;
(...)
I apply this script to my .tex files to correct all mistakes and overwrite my original .tex file. But, sometimes I would like the script to ask me to confirm every change, that is, for every matching regexp I would like the script to ask me if I want to proceed with the modification. I am sure there is an option for that, but I have not been able to find it yet. Thus, I would greatly appreciate any help or hints to solve this problem. Many thanks,
The solution is probably to not use sed. 'aspell' has a tex mode, so it can spell check your tex source files without tripping over the markup language, and it can work interactively.
In fact my script performs more advanced modifications than just correcting simple spelling mistakes (which I could clearly do with any spell checker). For example,
# replace (...)^ by {(...)}^;
s/\(([^)(]*)\)\^/{\1}\^/g;
# replace max by \max in equations (only if they are delimited by $ symbols);
s/\(\$[^\$]*[^\\]\)max\([^i][^\$]*\$\)/\1\\max\2/g;
I could translate my script to another language though, but I'd like to keep a list of regular expressions separate from the program files, so that it is easier for non-programmers to add new regexp and above all that the list of regexp is easily reusable. Any suggestion about the language to use to do that ?
You could, I suppose, run each sed command seperately, outputting to a different file, then run diff on the original and the new file, and ask if the changes are OK. Pretty trivial to script, but it's gonna be slow if you've got a lot of commands.
You might be able to do something a bit more elegant with awk, though.
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.