I’d like to accomplish this with a shell script. Here’s what my file looks like:
1
2
3
4
5
6
7
8
9
I want to convert it to be:
1 2 3
4 5 6
7 8 9
It's bigger than that, so I need something generic that works for a long file.
Thanks!
Here is one way:
awk 'NR%3!=0{printf "%s ",$1;next}1' inputFile
You can do that with paste, for example:
seq 9 | paste - - - -d ' '
The 3 dashes are to have 3 columns. You add or remove dashes to have more or fewer columns.
The -d ' ' is to separate the columns by space, because the default is tab.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With