ピボットファイルの値

ピボットファイルの値

最初の列がキーであるファイルがあります。行には最大2800の区切り文字を含めることができます。データを行から列に変換する必要があります。以下は、サンプル入力と希望の出力です。

ソースファイル

123,A,B,,,,AC,DF,,,,,,,,,,,,n 
567,A,B,,C,D,,,,,,,,, 7
89,C,B

出力

123,A
123,B
123,
123,
.
.
123,AC
123,DF
567,A
567,B
567,C
567,D
567,7
89,C
89,B

アドバイスしてください。

ベストアンサー1

ミラーの使用(http://johnkerl.org/miller/doc/)と

mlr --nidx --fs "," reshape -r '[^1]' -o item,value \
then filter -S -x '$value==""' \
then cut -f 1,value input.txt

あなたは

123,A
123,B
123,AC
123,DF
123,n
567,A
567,B
567,C
567,D
567, 7
89,C
89,B

null値も必要な場合は、次のようになります。

mlr --nidx --fs "," reshape -r '[^1]' -o item,value \
then cut -f 1,value input.txt

あなたはやる

123,A
123,B
123,
123,
123,
123,AC
123,DF
123,
123,
123,
123,
123,
123,
123,
123,
123,
123,
123,n
567,A
567,B
567,
567,C
567,D
567,
567,
567,
567,
567,
567,
567,
567, 7
89,C
89,B

おすすめ記事