ChapelCone56
ChapelCone56

Reputation: 37

How can I combine two multi-line output commands?

I have two commands that each output multiple lines, and I would like to combine them in a way that has a single space in-between each combined line.

These over sized commands are supposed to import an airodump-ng csv file, then extract two columns of data from the file. Then, they cleanup any extra characters I don't need.

  1. sed -n '/Station/q;p' schoolscan-02.csv | sed '/^[[:space:]]$/d' | sed -n '1!p' | awk -F "\",\"*" '{print $4}' | tr -d ' '

  2. sed -n '/Station/q;p' schoolscan-02.csv | sed '/^[[:space:]]$/d' | sed -n '1!p' | awk -F "\",\"*" '{print $1}'

Command #1 outputs:

a

b

c

d

And command #2 outputs:

1

2

3

4

I want the output to look like:

a 1

b 2

c 3

d 4

What command can I use to combine the two of these commands in such a way?

Upvotes: 0

Views: 713

Answers (2)

Poshi
Poshi

Reputation: 5762

Use paste and feed it both streams (one for command):

paste -d' ' <(sed -n '/Station/q;p' schoolscan-02.csv | sed '/^[[:space:]]$/d' | sed -n '1!p' | awk -F "\",\"*" '{print $4}' | tr -d ' ') <(sed -n '/Station/q;p' schoolscan-02.csv | sed '/^[[:space:]]$/d' | sed -n '1!p' | awk -F "\",\"*" '{print $1}')

Anyways, I can see that tne input to both awks is the same. I'm pretty sure you can accomplish your objectives with a single execution of awk.

Upvotes: 1

Felix
Felix

Reputation: 1905

Given that your programs' respective output lies in the files 1 and 2, you can combine them line-by-line using paste like this:

paste -d' ' 1 2

Upvotes: 0

Related Questions