mirror of
https://github.com/johnkerl/miller.git
synced 2026-01-23 02:14:13 +00:00
mlr cat --filename / --filenum (#1080)
* mlr cat --filename / --filenum * codespell
This commit is contained in:
parent
7be37aeb09
commit
dafec6dc09
18 changed files with 84 additions and 12 deletions
|
|
@ -8,3 +8,4 @@ numer
|
|||
Wit
|
||||
te
|
||||
wee
|
||||
RO
|
||||
|
|
|
|||
|
|
@ -286,7 +286,7 @@ bin_lo bin_hi flag_count u_count v_count
|
|||
1.0900000000000003 1.1900000000000002 0 0 25
|
||||
</pre>
|
||||
|
||||
Look at univariate stats by color and shape. In particular, color-dependent flag probabilities pop out, aligning with their original Bernoulli probablities from the data-generator script:
|
||||
Look at univariate stats by color and shape. In particular, color-dependent flag probabilities pop out, aligning with their original Bernoulli probabilities from the data-generator script:
|
||||
|
||||
<pre class="pre-highlight-in-pair">
|
||||
<b>mlr --opprint stats1 -a min,mean,max -f flag,u,v -g color \</b>
|
||||
|
|
|
|||
|
|
@ -93,7 +93,7 @@ GENMD-RUN-COMMAND
|
|||
mlr --opprint histogram -f flag,u,v --lo -0.1 --hi 1.1 --nbins 12 data/colored-shapes.dkvp
|
||||
GENMD-EOF
|
||||
|
||||
Look at univariate stats by color and shape. In particular, color-dependent flag probabilities pop out, aligning with their original Bernoulli probablities from the data-generator script:
|
||||
Look at univariate stats by color and shape. In particular, color-dependent flag probabilities pop out, aligning with their original Bernoulli probabilities from the data-generator script:
|
||||
|
||||
GENMD-RUN-COMMAND
|
||||
mlr --opprint stats1 -a min,mean,max -f flag,u,v -g color \
|
||||
|
|
|
|||
|
|
@ -905,6 +905,8 @@ VERBS
|
|||
-n Prepend field "n" to each record with record-counter starting at 1.
|
||||
-N {name} Prepend field {name} to each record with record-counter starting at 1.
|
||||
-g {a,b,c} Optional group-by-field names for counters, e.g. a,b,c
|
||||
--filename Prepend current filename to each record.
|
||||
--filenum Prepend current filenum (1-up) to each record.
|
||||
-h|--help Show this message.
|
||||
|
||||
check
|
||||
|
|
@ -3280,5 +3282,5 @@ SEE ALSO
|
|||
|
||||
|
||||
|
||||
2022-08-14 MILLER(1)
|
||||
2022-08-20 MILLER(1)
|
||||
</pre>
|
||||
|
|
|
|||
|
|
@ -884,6 +884,8 @@ VERBS
|
|||
-n Prepend field "n" to each record with record-counter starting at 1.
|
||||
-N {name} Prepend field {name} to each record with record-counter starting at 1.
|
||||
-g {a,b,c} Optional group-by-field names for counters, e.g. a,b,c
|
||||
--filename Prepend current filename to each record.
|
||||
--filenum Prepend current filenum (1-up) to each record.
|
||||
-h|--help Show this message.
|
||||
|
||||
check
|
||||
|
|
@ -3259,4 +3261,4 @@ SEE ALSO
|
|||
|
||||
|
||||
|
||||
2022-08-14 MILLER(1)
|
||||
2022-08-20 MILLER(1)
|
||||
|
|
|
|||
|
|
@ -84,7 +84,7 @@ For `mlr put` and `mlr filter`, parse-error messages now include location inform
|
|||
|
||||
<pre class="pre-non-highlight-non-pair">
|
||||
mlr: cannot parse DSL expression.
|
||||
Parse error on token ">" at line 63 columnn 7.
|
||||
Parse error on token ">" at line 63 column 7.
|
||||
</pre>
|
||||
|
||||
### Scripting
|
||||
|
|
|
|||
|
|
@ -68,7 +68,7 @@ For `mlr put` and `mlr filter`, parse-error messages now include location inform
|
|||
|
||||
GENMD-CARDIFY
|
||||
mlr: cannot parse DSL expression.
|
||||
Parse error on token ">" at line 63 columnn 7.
|
||||
Parse error on token ">" at line 63 column 7.
|
||||
GENMD-EOF
|
||||
|
||||
### Scripting
|
||||
|
|
|
|||
|
|
@ -179,6 +179,8 @@ Options:
|
|||
-n Prepend field "n" to each record with record-counter starting at 1.
|
||||
-N {name} Prepend field {name} to each record with record-counter starting at 1.
|
||||
-g {a,b,c} Optional group-by-field names for counters, e.g. a,b,c
|
||||
--filename Prepend current filename to each record.
|
||||
--filenum Prepend current filenum (1-up) to each record.
|
||||
-h|--help Show this message.
|
||||
</pre>
|
||||
|
||||
|
|
|
|||
|
|
@ -342,7 +342,7 @@ JSON vs. tabular formats](flatten-unflatten.md) for more information.
|
|||
The reason for this is part historical and part technical. As we'll see below,
|
||||
you can do lots of syntactical things with `emit`, `emitp`, and `emitf`,
|
||||
including printing them side-by-side, index them, redirect the output to files,
|
||||
etc. What this means syntatically is that Miller's parser needs to handle all
|
||||
etc. What this means syntactically is that Miller's parser needs to handle all
|
||||
sorts of commas, parentheses, and so on:
|
||||
|
||||
<pre class="pre-non-highlight-non-pair">
|
||||
|
|
|
|||
|
|
@ -153,7 +153,7 @@ JSON vs. tabular formats](flatten-unflatten.md) for more information.
|
|||
The reason for this is part historical and part technical. As we'll see below,
|
||||
you can do lots of syntactical things with `emit`, `emitp`, and `emitf`,
|
||||
including printing them side-by-side, index them, redirect the output to files,
|
||||
etc. What this means syntatically is that Miller's parser needs to handle all
|
||||
etc. What this means syntactically is that Miller's parser needs to handle all
|
||||
sorts of commas, parentheses, and so on:
|
||||
|
||||
GENMD-CARDIFY
|
||||
|
|
|
|||
|
|
@ -247,6 +247,8 @@ Options:
|
|||
-n Prepend field "n" to each record with record-counter starting at 1.
|
||||
-N {name} Prepend field {name} to each record with record-counter starting at 1.
|
||||
-g {a,b,c} Optional group-by-field names for counters, e.g. a,b,c
|
||||
--filename Prepend current filename to each record.
|
||||
--filenum Prepend current filenum (1-up) to each record.
|
||||
-h|--help Show this message.
|
||||
</pre>
|
||||
|
||||
|
|
|
|||
|
|
@ -30,6 +30,8 @@ func transformerCatUsage(
|
|||
fmt.Fprintf(o, "-n Prepend field \"n\" to each record with record-counter starting at 1.\n")
|
||||
fmt.Fprintf(o, "-N {name} Prepend field {name} to each record with record-counter starting at 1.\n")
|
||||
fmt.Fprintf(o, "-g {a,b,c} Optional group-by-field names for counters, e.g. a,b,c\n")
|
||||
fmt.Fprintf(o, "--filename Prepend current filename to each record.\n")
|
||||
fmt.Fprintf(o, "--filenum Prepend current filenum (1-up) to each record.\n")
|
||||
fmt.Fprintf(o, "-h|--help Show this message.\n")
|
||||
}
|
||||
|
||||
|
|
@ -50,6 +52,8 @@ func transformerCatParseCLI(
|
|||
doCounters := false
|
||||
counterFieldName := ""
|
||||
var groupByFieldNames []string = nil
|
||||
doFileName := false
|
||||
doFileNum := false
|
||||
|
||||
for argi < argc /* variable increment: 1 or 2 depending on flag */ {
|
||||
opt := args[argi]
|
||||
|
|
@ -74,6 +78,12 @@ func transformerCatParseCLI(
|
|||
} else if opt == "-g" {
|
||||
groupByFieldNames = cli.VerbGetStringArrayArgOrDie(verb, opt, args, &argi, argc)
|
||||
|
||||
} else if opt == "--filename" {
|
||||
doFileName = true
|
||||
|
||||
} else if opt == "--filenum" {
|
||||
doFileNum = true
|
||||
|
||||
} else {
|
||||
transformerCatUsage(os.Stderr)
|
||||
os.Exit(1)
|
||||
|
|
@ -89,6 +99,8 @@ func transformerCatParseCLI(
|
|||
doCounters,
|
||||
counterFieldName,
|
||||
groupByFieldNames,
|
||||
doFileName,
|
||||
doFileNum,
|
||||
)
|
||||
if err != nil {
|
||||
fmt.Fprintln(os.Stderr, err)
|
||||
|
|
@ -107,6 +119,9 @@ type TransformerCat struct {
|
|||
countsByGroup map[string]int64
|
||||
counterFieldName string
|
||||
|
||||
doFileName bool
|
||||
doFileNum bool
|
||||
|
||||
recordTransformerFunc RecordTransformerFunc
|
||||
}
|
||||
|
||||
|
|
@ -115,6 +130,8 @@ func NewTransformerCat(
|
|||
doCounters bool,
|
||||
counterFieldName string,
|
||||
groupByFieldNames []string,
|
||||
doFileName bool,
|
||||
doFileNum bool,
|
||||
) (*TransformerCat, error) {
|
||||
|
||||
if counterFieldName != "" {
|
||||
|
|
@ -127,6 +144,8 @@ func NewTransformerCat(
|
|||
counter: 0,
|
||||
countsByGroup: make(map[string]int64),
|
||||
counterFieldName: counterFieldName,
|
||||
doFileName: doFileName,
|
||||
doFileNum: doFileNum,
|
||||
}
|
||||
|
||||
if !doCounters {
|
||||
|
|
@ -151,7 +170,12 @@ func (tr *TransformerCat) Transform(
|
|||
outputDownstreamDoneChannel chan<- bool,
|
||||
) {
|
||||
HandleDefaultDownstreamDone(inputDownstreamDoneChannel, outputDownstreamDoneChannel)
|
||||
tr.recordTransformerFunc(inrecAndContext, outputRecordsAndContexts, inputDownstreamDoneChannel, outputDownstreamDoneChannel)
|
||||
tr.recordTransformerFunc(
|
||||
inrecAndContext,
|
||||
outputRecordsAndContexts,
|
||||
inputDownstreamDoneChannel,
|
||||
outputDownstreamDoneChannel,
|
||||
)
|
||||
}
|
||||
|
||||
// ----------------------------------------------------------------
|
||||
|
|
@ -161,6 +185,14 @@ func (tr *TransformerCat) simpleCat(
|
|||
inputDownstreamDoneChannel <-chan bool,
|
||||
outputDownstreamDoneChannel chan<- bool,
|
||||
) {
|
||||
if !inrecAndContext.EndOfStream {
|
||||
if tr.doFileName {
|
||||
inrecAndContext.Record.PrependCopy("filename", mlrval.FromString(inrecAndContext.Context.FILENAME))
|
||||
}
|
||||
if tr.doFileNum {
|
||||
inrecAndContext.Record.PrependCopy("filenum", mlrval.FromInt(inrecAndContext.Context.FILENUM))
|
||||
}
|
||||
}
|
||||
outputRecordsAndContexts.PushBack(inrecAndContext)
|
||||
}
|
||||
|
||||
|
|
@ -176,6 +208,13 @@ func (tr *TransformerCat) countersUngrouped(
|
|||
tr.counter++
|
||||
key := tr.counterFieldName
|
||||
inrec.PrependCopy(key, mlrval.FromInt(tr.counter))
|
||||
|
||||
if tr.doFileName {
|
||||
inrec.PrependCopy("filename", mlrval.FromString(inrecAndContext.Context.FILENAME))
|
||||
}
|
||||
if tr.doFileNum {
|
||||
inrec.PrependCopy("filenum", mlrval.FromInt(inrecAndContext.Context.FILENUM))
|
||||
}
|
||||
}
|
||||
outputRecordsAndContexts.PushBack(inrecAndContext)
|
||||
}
|
||||
|
|
@ -208,6 +247,13 @@ func (tr *TransformerCat) countersGrouped(
|
|||
|
||||
key := tr.counterFieldName
|
||||
inrec.PrependCopy(key, mlrval.FromInt(counter))
|
||||
|
||||
if tr.doFileName {
|
||||
inrec.PrependCopy("filename", mlrval.FromString(inrecAndContext.Context.FILENAME))
|
||||
}
|
||||
if tr.doFileNum {
|
||||
inrec.PrependCopy("filenum", mlrval.FromInt(inrecAndContext.Context.FILENUM))
|
||||
}
|
||||
}
|
||||
outputRecordsAndContexts.PushBack(inrecAndContext)
|
||||
}
|
||||
|
|
|
|||
|
|
@ -884,6 +884,8 @@ VERBS
|
|||
-n Prepend field "n" to each record with record-counter starting at 1.
|
||||
-N {name} Prepend field {name} to each record with record-counter starting at 1.
|
||||
-g {a,b,c} Optional group-by-field names for counters, e.g. a,b,c
|
||||
--filename Prepend current filename to each record.
|
||||
--filenum Prepend current filenum (1-up) to each record.
|
||||
-h|--help Show this message.
|
||||
|
||||
check
|
||||
|
|
@ -3259,4 +3261,4 @@ SEE ALSO
|
|||
|
||||
|
||||
|
||||
2022-08-14 MILLER(1)
|
||||
2022-08-20 MILLER(1)
|
||||
|
|
|
|||
|
|
@ -2,12 +2,12 @@
|
|||
.\" Title: mlr
|
||||
.\" Author: [see the "AUTHOR" section]
|
||||
.\" Generator: ./mkman.rb
|
||||
.\" Date: 2022-08-14
|
||||
.\" Date: 2022-08-20
|
||||
.\" Manual: \ \&
|
||||
.\" Source: \ \&
|
||||
.\" Language: English
|
||||
.\"
|
||||
.TH "MILLER" "1" "2022-08-14" "\ \&" "\ \&"
|
||||
.TH "MILLER" "1" "2022-08-20" "\ \&" "\ \&"
|
||||
.\" -----------------------------------------------------------------
|
||||
.\" * Portability definitions
|
||||
.\" ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
||||
|
|
@ -1071,6 +1071,8 @@ Options:
|
|||
-n Prepend field "n" to each record with record-counter starting at 1.
|
||||
-N {name} Prepend field {name} to each record with record-counter starting at 1.
|
||||
-g {a,b,c} Optional group-by-field names for counters, e.g. a,b,c
|
||||
--filename Prepend current filename to each record.
|
||||
--filenum Prepend current filenum (1-up) to each record.
|
||||
-h|--help Show this message.
|
||||
.fi
|
||||
.if n \{\
|
||||
|
|
|
|||
|
|
@ -42,6 +42,8 @@ Options:
|
|||
-n Prepend field "n" to each record with record-counter starting at 1.
|
||||
-N {name} Prepend field {name} to each record with record-counter starting at 1.
|
||||
-g {a,b,c} Optional group-by-field names for counters, e.g. a,b,c
|
||||
--filename Prepend current filename to each record.
|
||||
--filenum Prepend current filenum (1-up) to each record.
|
||||
-h|--help Show this message.
|
||||
|
||||
================================================================
|
||||
|
|
|
|||
1
test/cases/verb-cat/0015/cmd
Normal file
1
test/cases/verb-cat/0015/cmd
Normal file
|
|
@ -0,0 +1 @@
|
|||
mlr cat --filename --filenum test/input/abixy
|
||||
0
test/cases/verb-cat/0015/experr
Normal file
0
test/cases/verb-cat/0015/experr
Normal file
10
test/cases/verb-cat/0015/expout
Normal file
10
test/cases/verb-cat/0015/expout
Normal file
|
|
@ -0,0 +1,10 @@
|
|||
filenum=1,filename=test/input/abixy,a=pan,b=pan,i=1,x=0.34679014,y=0.72680286
|
||||
filenum=1,filename=test/input/abixy,a=eks,b=pan,i=2,x=0.75867996,y=0.52215111
|
||||
filenum=1,filename=test/input/abixy,a=wye,b=wye,i=3,x=0.20460331,y=0.33831853
|
||||
filenum=1,filename=test/input/abixy,a=eks,b=wye,i=4,x=0.38139939,y=0.13418874
|
||||
filenum=1,filename=test/input/abixy,a=wye,b=pan,i=5,x=0.57328892,y=0.86362447
|
||||
filenum=1,filename=test/input/abixy,a=zee,b=pan,i=6,x=0.52712616,y=0.49322129
|
||||
filenum=1,filename=test/input/abixy,a=eks,b=zee,i=7,x=0.61178406,y=0.18788492
|
||||
filenum=1,filename=test/input/abixy,a=zee,b=wye,i=8,x=0.59855401,y=0.97618139
|
||||
filenum=1,filename=test/input/abixy,a=hat,b=wye,i=9,x=0.03144188,y=0.74955076
|
||||
filenum=1,filename=test/input/abixy,a=pan,b=wye,i=10,x=0.50262601,y=0.95261836
|
||||
Loading…
Add table
Add a link
Reference in a new issue