简体   繁体   中英

awk print two variables on the same line

I need to use awk to print two variables on the same line

foo=multiline pattern
bar=multiline pattern

awk -v foo="$foo" -v bar="$bar" 'BEGIN {print foo bar}'

This Output:

foo1
foo2
foo3
bar1
bar2
bar3

I need to get

foo1 bar1
foo2 bar2
foo3 bar3

您可以将paste用于并行输出:

paste <(echo "$foo") <(echo "$bar")

No need to complicate things. If you want to split the file into two columns with space delimiter in between do this.

$ pr -2ts' ' <foobar

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM