米勒: ofs= "n" ?

  • 本文关键字:ofs 米勒 csv miller
  • 更新时间 :
  • 英文 :


假设我有:

cat file
"Field 1, Line 1",Field 2,"Field 3, Line 1"
"Field 1, Line 2",Field 2,"Field 3, Line 2"

对于Miller,我想生产:

"Field 1, Line 1"
"Field 2"
"Field 3, Line 1"
"Field 1, Line 2"
"Field 2"
"Field 3, Line 2"

我试过了:

mlr --csv -N  --ofs lf --quote-all cat file

没有输出

作为一种变通方法,我可以这样做:

mlr --csv -N  --ofs pipe --quote-all cat file | sed 's/"|"/"n"/g'
或者使用ruby:
ruby -r csv -e 'CSV.parse($<.read).flatten.each{|r| puts [r].to_csv(force_quotes: true)}' file

但它确实觉得我应该能够一次只看一个csv文件字段(并忽略记录)与米勒?

您可以重塑和枚举:

mlr --csv --quote-all -N reshape -r ".*" -o a,b  input.csv
"1","Field 1, Line 1"
"2","Field 2"
"3","Field 3, Line 1"
"1","Field 1, Line 2"
"2","Field 2"
"3","Field 3, Line 2"

然后剪掉第一列(在这种情况下cut -f b保留第二列命名为b):

mlr --csv --quote-all -N reshape -r ".*" -o a,b then cut -f b input.csv

:

"Field 1, Line 1"
"Field 2"
"Field 3, Line 1"
"Field 1, Line 2"
"Field 2"
"Field 3, Line 2"

虽然Miller对CSV格式的--ifs--ofs进行了不同的处理,但--ofs lf不输出任何错误信息感觉就像一个bug…

作为一种解决方法,我会将输入记录拆分为多个单字段记录:

mlr -c -N --quote-all filter -q 'for (k,v in $*) {emit {1:v}}'
"Field 1, Line 1"
"Field 2"
"Field 3, Line 1"
"Field 1, Line 2"
"Field 2"
"Field 3, Line 2"

相关内容

  • 没有找到相关文章

最新更新