English Deutsch Français Italiano Español Português 繁體中文 Bahasa Indonesia Tiếng Việt ภาษาไทย
All categories

I need to create a script that will automatically edit the contents of a file

2007-06-21 15:18:17 · 3 answers · asked by kido villena 2 in Computers & Internet Programming & Design

3 answers

I think you are probably comming at this from the wrong direction... i have a feeling VI is a far too powerful tool for waht you want to do... you can send a stream of characters to VI using unix piping, for example if you have a file with the correct characters in it you can type: vi /file/to/edit < /commands/file
and make sure your commands file ends with 'esc':wq to write changes

however writing a perl (www.perl.org) script to do what you want using regular expressions (see: www.regular-expressions.info) would probably be 100 times easier, and significantly more likely to work, as it's not easy getting those special characters into a text file using standard tools like vi which swallow, for example, 'esc' characters
p.s. i have no idea if that will actually work, but it should, if you can get the right characters into the command file...

2007-06-21 15:34:33 · answer #1 · answered by toby d 1 · 0 0

In intro books I once read, what you intend to do is delegated to the ED editor, it was a left over from non-monitor days of early UNIX computing and a granddaddy of DOS's EDLIN, found to be handy for exactly your purpose, nothing else.

2007-06-21 22:30:15 · answer #2 · answered by Andy T 7 · 0 0

I use this in shell scripts to individualize users config files.
perl -p -i -e 's/change this/..to this/g'
Also can be used at the command line.

2007-06-24 11:36:24 · answer #3 · answered by Barry B 2 · 0 0

fedest.com, questions and answers