Ask Ubuntu is a question and answer site for Ubuntu users and developers. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

is there a tool that can help me to batch edit text files in a certain folder?

I need to delete or insert snippets repeatedly in lots of html files and restructure them.

Thanks in advance!

share|improve this question
up vote 2 down vote accepted

As Julian showed, sed is the right tool for that.

I just want to add two remarks:

you can process multiple files at once, just by providing list of files:

sed -i.bak 's/old text/new text/' dir1/*.html dir2/*.html

Also, if you need to work with some Snippets manually, you can enable Snippets plugin in gedit:

Edit -> Preferences -> Plugins -> Snippets. You might find it handy.

share|improve this answer

sed, the stream editor, is your friend here. For example.

sed -i.bak -e's/<p id="first"/<p id="second"/' file.html

would change all the paragraphs with the id 'first' to id 'second' in file.html, and create file.html.bak into the bargain.

share|improve this answer
+1 sed lives for this kind of job. – Richard Holloway Sep 2 '11 at 14:39
ed also can be a viable solution, if the stream requirement can be relaxed. – enzotib Sep 2 '11 at 14:41
Thanks a lot! I'll check it out. – YSN Sep 2 '11 at 16:44

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.