Command-Line

連接來自多個變數的多個列?

  • April 19, 2017

var $abc 包含:

abc  jkl
def  mno
ghi  pqr

var $def 包含:

stu
vwx
yz

預期輸出:

abc  jkl  stu
def  mno  vwx
ghi  pqr  yz

heemayl的解決方案:

我試過paste <(echo "$abc") <(echo "$def")了,但它給出的輸出如下

ASFSFGFGGRRFDFFFFFH     33566
AHSHDFFBORDASHFYEHFYUCH 33568
FASFSSFHJUYRT   33371
FASIFIDFGGGDDDDD        33364
AFDDDGGGGGDER   33371
FDGGGGHJJK      16225
AISJFKDJFKDDKFJKDJFF    33568
KDFJKDJFKDJFKDFJK       33567

如何正確對齊第二列?

解決方案:

paste <(echo "$abc") <(echo "$def") | column -t

使用paste, 在程序替換的幫助下獲取兩個文件描述符以paste進行操作:

paste <(echo "$abc") <(echo "$def")

小心引用變數。

例子:

$ echo "$abc"
abc jkl
def mno
ghi pqr

$ echo "$def"
stu
vwx
yz

$ paste <(echo "$abc") <(echo "$def")
abc jkl stu
def mno vwx
ghi pqr yz

引用自:https://unix.stackexchange.com/questions/359833