spakin/awk

Ways to control output

suntong opened this issue · 3 comments

Any plan to implement the awk-inplace-modification feature, in near or far future?

I need such a feature now, so I guess I have to scratch my own itch. However I took a look at awk godoc, but didn't find a way to control its output.

Comments? Thx.

I wasn't planning on it. It should be easy enough, though, for you to initialize the Script's Output field to a temporary file (say, with ioutil.TempFile) then os.Rename it back to the original file name at the end of the script, no?

A problem with trying to automate this feature is that the Go package doesn't know the name of the original file. In fact, because a Script takes an io.Writer to write to, it may not even be a file.

— Scott

Ok. Thanks for describing how to do it ourselves.

FTA, I found that the best way to deal with this inplace-modification situation is to use awk with the pipe package. Ref https://github.com/suntong/lang/blob/master/lang/Go/src/sys/Pipe_Awk.go for a working sample how they can work together.