A
A
Alexander Semenenko2019-07-29 13:18:13
linux
Alexander Semenenko, 2019-07-29 13:18:13

Is it possible to make a table from the output in bash?

I can welcome this output:
2125
node1
2058
node2
258545
node1
to this output:
2125 node1
2058 node2
258545 node1
So that the first line goes into the first column, the second into the second, the third again into the first, etc.

Answer the question

In order to leave comments, you need to log in

2 answer(s)
D
Dmitry, 2019-07-29
@semenenko88

~  cat file.txt
1
one
2
two
3
tree
 ~  awk '{printf "%s" (NR%2==0?RS:FS),$1}' file.txt
1 one
2 two
3 tree
 ~ 

E
Eugene, 2019-07-29
@Evgenym

If the data format is completely like this: numbers alternate with lines, then I would try replacing with regular expressions. I would output the data to a text file, and then process it with sed.
I would search for lines starting with a digit like ^(\d.+)\n
And remove the newline at the end, i.e. I would change it to \1
After the unit there is a space. Works in Notepad++.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question