Skip to content

Instantly share code, notes, and snippets.

@mamemomonga
Created June 8, 2020 03:10
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save mamemomonga/b5002c7e96db46803d954c928b65b9f8 to your computer and use it in GitHub Desktop.
Save mamemomonga/b5002c7e96db46803d954c928b65b9f8 to your computer and use it in GitHub Desktop.
先頭がフィールドのTSVデータを読みやすい形に変換する
#!/usr/bin/perl
# 先頭がフィールドのTSVデータを読みやすい形に変換する
# 以下のようなTSVデータをKey:Valueの表示に変換する。
#
# field1 field2 field3
# data1 data2 data3
# data1 data2 data3
#
# 使い方
# pbpaste | ./tsv-convert.pl
use strict;
use warnings;
use feature 'say';
my @data=<>;
my @fields=split(/\t/,shift @data);
foreach my $d (@data) {
my @lines=split(/\t/,$d);
for(my $i=0;$i<$#fields;$i++) {
printf("%20s: %s\n",$fields[$i], $lines[$i]);
}
say "-------------------------------------------------";
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment