I am working on an outage script and I run a command from the command line which tells me the amount of generator failures in my market. The output of this command only gives me three digits to identify the site by. I have a master list of all sites in a separate file, call it list.txt. If my command appends to file outagereport.txt, I want to use SED or something else to look at the output of that file and match it to the sites in the list.txt file and then modify the original file.
So, lets say that I run the following command:
TICLI "op:alarm,all" | { printf "Austin Generators Running Alarms:\n" && grep GEN | grep RUN || printf "Austin Generator Alarms: Zero \n"; }>> AustinOutageReport.txt
and my list.txt file has the following entry in it: Sitename-market-0040-awesomesite
How can I get UNIX to look at list.txt and replace the text of cell for generator running with the text of list.txt that says Sitename-market-0040-awesomesite?
My thought was to use a sed substitute command for this but if I do that I will have a script with over 1800 sed substitutes.
Yes, it would be good to step back at this point and do more research.
I solved this problem through using sed.
I created a sed script which contains about 3,400 sed commands like the one below:
sed -i.bak 's/143 ISOL INDT/SA 4119-4-4-0143-ST_ALBANS/' masterreport.txt
This searches my file of master report and modifies the text of the original report with the site names in my sed script. It takes less time than I thought. thanks for all the help.
Invoking awk once to make up to 3400 changes to a file is 99.94% likely to run MUCH faster (by a few orders of magnitude) than invoking sed 3400 times to perform the same task. If you would give us clear, explicit descriptions of what the files being processed really look like (instead of showing us the output you get from running a script with unspecified input file formats), we would be happy to try to help you solve your problem more efficiently.
The key to writing efficient, reliable software is to know what the input looks like, what output needs to be produced, and what constraints can be assumed concerning the inputs and outputs.
Don, while he might be saying he's running sed 3400 times, if instead they are 3400 sed commands in single invocation, it will run faster than your awk (just saying).
and interpreted it as "a shell script containing 3,400 sed commands ...". If jbrass meant what you're describing, I would have expected it to be something more like: "a sed script which contains about 3,400 substitute commands...".