diff --git a/internal/pkg/mlrval/mlrmap_print.go b/internal/pkg/mlrval/mlrmap_print.go index 5ab7c2d5a..d565b270d 100644 --- a/internal/pkg/mlrval/mlrmap_print.go +++ b/internal/pkg/mlrval/mlrmap_print.go @@ -12,28 +12,28 @@ func (mlrmap *Mlrmap) Print() { os.Stdout.WriteString("\n") } func (mlrmap *Mlrmap) Fprint(file *os.File) { - (*file).WriteString(mlrmap.ToDKVPString()) + (*file).WriteString(mlrmap.ToDKVPString(",", "=")) } -func (mlrmap *Mlrmap) ToDKVPString() string { +func (mlrmap *Mlrmap) ToDKVPString(ofs, ops string) string { var buffer bytes.Buffer // stdio is non-buffered in Go, so buffer for ~5x speed increase for pe := mlrmap.Head; pe != nil; pe = pe.Next { buffer.WriteString(pe.Key) - buffer.WriteString("=") + buffer.WriteString(ops) buffer.WriteString(pe.Value.String()) if pe.Next != nil { - buffer.WriteString(",") + buffer.WriteString(ofs) } } return buffer.String() } -func (mlrmap *Mlrmap) ToNIDXString() string { +func (mlrmap *Mlrmap) ToNIDXString(ofs string) string { var buffer bytes.Buffer // stdio is non-buffered in Go, so buffer for ~5x speed increase for pe := mlrmap.Head; pe != nil; pe = pe.Next { buffer.WriteString(pe.Value.String()) if pe.Next != nil { - buffer.WriteString(",") + buffer.WriteString(ofs) } } return buffer.String() diff --git a/internal/pkg/transformers/grep.go b/internal/pkg/transformers/grep.go index 6e692364a..afcfc75d3 100644 --- a/internal/pkg/transformers/grep.go +++ b/internal/pkg/transformers/grep.go @@ -51,7 +51,7 @@ func transformerGrepParseCLI( pargi *int, argc int, args []string, - _ *cli.TOptions, + options *cli.TOptions, doConstruct bool, // false for first pass of CLI-parse, true for second pass ) IRecordTransformer { @@ -122,6 +122,8 @@ func transformerGrepParseCLI( regexp, invert, valuesOnly, + options.WriterOptions.OFS, + options.WriterOptions.OPS, ) if err != nil { fmt.Fprintln(os.Stderr, err) @@ -136,17 +138,23 @@ type TransformerGrep struct { regexp *regexp.Regexp invert bool valuesOnly bool + ofs string + ops string } func NewTransformerGrep( regexp *regexp.Regexp, invert bool, valuesOnly bool, + ofs string, + ops string, ) (*TransformerGrep, error) { tr := &TransformerGrep{ regexp: regexp, invert: invert, valuesOnly: valuesOnly, + ofs: ofs, + ops: ops, } return tr, nil } @@ -164,9 +172,9 @@ func (tr *TransformerGrep) Transform( inrec := inrecAndContext.Record var inrecAsString string if tr.valuesOnly { - inrecAsString = inrec.ToNIDXString() + inrecAsString = inrec.ToNIDXString(tr.ofs) } else { - inrecAsString = inrec.ToDKVPString() + inrecAsString = inrec.ToDKVPString(tr.ofs, tr.ops) } matches := tr.regexp.Match([]byte(inrecAsString)) if tr.invert {