View Single Post
  #1   (View Single Post)  
Old 24th August 2010
guitarscn guitarscn is offline
Package Pilot
Join Date: Oct 2008
Posts: 166
Default Writing a simple script to edit text files and execute commands

Okay this will probably have multiple parts to it but I don't really want to trouble you guys with more help because I'm a total noob so I can just do the first part by hand (it's just editing a few hundred lines of text in a file; I have to do the same thing on each line and I'm sure there's a scripted solution for it but I can spare a couple hours).

So basically I have a file with several hundred lines, and each line is only 2-3 words.

I need the script to do these things in order:

1) kill process1
2) put the 1st line of this file list into already existing text file #1 (requires root to write): the line it needs to write to is like: "option LINE1" where the 1st line has to be written where 'LINE1' is, somewhere in this text file
3) save this text file
4) put the 1st line of this file list into existing text file #2: the line is like "set = { opt1 = LINE1; opt2 = LINE1; opt3 = LINE1; }" and again I want the 1st line to be filled in all where 'LINE1' says
5) save text file
6) start process1
7) run a certain command in shell which will execute a CLI program and leave it running (I don't think it can be run in the background because I tried starting it with the '&' sign at the end and it ran but it didn't connect the way it properly was supposed to)
8) repeat but use the next line in the file list

What programming language would be the quickest and easiest way to write something like this? It doesn't have to be fancy or anything, just work even if it's dirty
Reply With Quote