Brandon S. Allbery KF8NH wrote: > On Nov 30, 2009, at 21:20 , Tom Limoncelli wrote: >> This sounds like a job of sed but my sed fu is weak. > > Not really; sed can be abused into that kind of conditionality, but > it's not simple. Redefine the spec so that an existing block is > deleted but the new block goes at the end always, and you have a > sed-type job. > > This can, on the other hand, be fairly easily done with awk. It's > still not a one-liner, though. I'm with Brandon on using awk. My definition of one line might be more flexible than his, using flags. something like this for your body awk '$2 == "BEGIN" {begun=1; print lines;} begun != 1 {print $0}; $2 == "END" {begun = 2;}
But you'll also want a BEGIN block that opens and reads in rc-addition.. Something like this: awk 'BEGIN {while (getline line < "/tmp/rc-addition") {lines = lines "\n" line}} putting it all together: awk 'BEGIN {while (getline line < "/tmp/rc-addition") {lines = lines "\n" line;}} $2 == "BEGIN" {begun=1; print lines;} begun != 1 {print $0}; $2 == "END" {begun = 2;} END {if (begun == 0) {print lines}}' /tmp/rc-machine The END also has a flag, so if it never found a start block, then it will print what you snarfed in from rc-addition. _______________________________________________ Discuss mailing list Discuss@lopsa.org http://lopsa.org/cgi-bin/mailman/listinfo/discuss This list provided by the League of Professional System Administrators http://lopsa.org/