LinuxQuestions.org
View the Most Wanted LQ Wiki articles.
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices

Reply
 
Search this Thread
Old 04-02-2009, 10:33 AM   #1
raimizou
LQ Newbie
 
Registered: Apr 2009
Posts: 7

Rep: Reputation: 0
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,

Regards,

Gilles
 
Old 04-02-2009, 10:49 AM   #2
ilikejam
Senior Member
 
Registered: Aug 2003
Location: Glasgow
Distribution: Fedora / Solaris
Posts: 3,109

Rep: Reputation: 96
Hi.

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.

Dave
 
Old 04-03-2009, 01:27 AM   #3
raimizou
LQ Newbie
 
Registered: Apr 2009
Posts: 7

Original Poster
Rep: Reputation: 0
Hi,

thanks for your reply ilikejam.

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 ?

Gilles
 
Old 04-03-2009, 05:03 AM   #4
ilikejam
Senior Member
 
Registered: Aug 2003
Location: Glasgow
Distribution: Fedora / Solaris
Posts: 3,109

Rep: Reputation: 96
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.

Dave
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Check if actions in bash shell script are performed well proNick Linux - Newbie 6 02-09-2009 07:25 PM
/etc/acpi/acpi_handler.sh and running a confirmation script. Romanus81 Slackware 10 01-21-2009 10:25 AM
bash script with grep and sed: sed getting filenames from grep odysseus.lost Programming 1 07-17-2006 11:36 AM
shell script asking for confirmation? bikov_k Programming 6 11-04-2005 02:16 AM
Bash script - confirmation option satimis Programming 4 10-21-2004 07:29 AM


All times are GMT -5. The time now is 05:08 AM.

Main Menu
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
identi.ca: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration