appending a file to another as a new column
追加の回答で以下のような回答があった。
awk 'NR==FNR{b[++n]=$0;next}FNR==n{t=","}{print $0 t, b[FNR]}' fileB fileA
う〜ん、見づらい。
NR==FNR というのは最初のファイルの読み込みを示しているわけですが・・・読みづらい。
この解答を書いた Ed 氏の awk で配列を使う際の注意書きの文書は面白い。(てか、Ed 氏は有名)
a) they're indexed by strings not numbers (so a[1] != a[01])
b) when you loop using the "in" operator to index an array, the order
isn't what you'd typically expect (so set "WHINY_USERS" or use "asort()"
or "asorti()" in gawk to get sorted output, or keep a separate index)
c) array accesses are very slow
だそうな。
# ま、「泣くのがいやなら、さ〜ぁ gawk」ってところか。(全然違います)
で、その後も続いて、
I'd definitely use/download gawk and get Arnold Robbins' book if you see
yourself doing more awk-ing in future.
誰か翻訳してくれないかなぁ。
というか、これも既に Obsolete なんですが、私も awk-ing (苦笑) するなら購入するかなぁ。
Effective awk Programming: Text Processing and Pattern Matching
- 作者: Arnold Robbins
- 出版社/メーカー: O'Reilly Media
- 発売日: 2001/05/15
- メディア: ペーパーバック
- クリック: 5回
- この商品を含むブログ (2件) を見る