SScast February 2016

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

Answers


karakfa February 2016

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


anubhava February 2016

You can use paste for side-by-side output:

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

Post Status

Asked in February 2016
Viewed 3,392 times
Voted 13
Answered 2 times

Search




Leave an answer