awk find/replace

Greetings all.

I have web site that has long option and switch lists. When I insert something new into these files, the lists need to be reordered. IE:

1 => apple
2 => pear
3 => bannana
4 => orange
---------------------
Add grape as #2

1 => apple
2 => grape
3 => pear
4 => bannana
5 => orange

In this example it is easy to reorder. However my files have close to 200 entries. Making the reordering very tedious and labor intensive.

What I am wondering, is it possible to use awk find/replace along with C to automate this process?

The idea would be to construct a while loop, find the next number to replace and replace it with the next higher number. Loop through the process until finished.

Does that sound like the easiest solution or is there something easier/better out there?

Thank you for your thoughts.
~Robert

Hi,

What scripting language are you using on your web server? php, python, perl ...?

If your pages are static, it won't be that easy. Possible but not easy.

Assuming the given format, you can work on something along the lines of ...

nawk  '$1==n { print n " => " s } $1>=n { $1++ } 1' n=2 s="grape" list_file