convert rows (with spaces) to columns

Hey all, I have a list in the format ;

variable length with spaces
more variable information
some more variable information

and I would like to transform that 'column' into rows ;

 variable length with spaces     more variable information     some more variable information 

Any assistance greatly appreciated !

$
$ # -e option displays "$" for end-of-line
$ cat -e f18
variable length with spaces    $
more variable information  $
some more variable information$
$
$
$ awk '{printf $0} END{print ""}' f18
variable length with spaces    more variable information  some more variable information
$
$
$ perl -lne 'printf; END{print}' f18
variable length with spaces    more variable information  some more variable information
$
$

tyler_durden

Another one, using paste:

$ paste -sd"\t"  file
variable length with spaces	more variable information	some more variable information

Thanks for the quick response men !

This is definately putting me on the right path.

What I am working on is a log for a bluetooth scanner and I probably
should have mentioned that there would be multiple lists (rows) which
are space separated (which makes the previously mentioned possibilities not perfect).

So the list I get it is ;

BD Address:     00:24:00:2C:00:76 [mode 1, clkoffset 0x27bc]
Device name:    Nokia Test 0
Device class:   Phone, Cellular (0x5a0204)

BD Address:     00:24:00:FB:00:9C [mode 1, clkoffset 0x3a75]
Device name:    Nokia Test 1
Device class:   Phone, Cellular (0x5a0204)

BD Address:     6C:00:02:00:97:00 [mode 1, clkoffset 0x324a]
Device name:    Nokia Test
Device class:   Phone, Cellular (0x520204)

So I would cut out the first column with ;

cut -c 17-

And am then seeking to have the the columns created per result as per;

00:24:00:FB:00:9C [mode 1, clkoffset 0x3a75]   Nokia Test 1   Phone, Cellular (0x520204)

Thanks again for the (very!) quick response and if you feel you have
"shown me the path", its all good, it has helped me think of different possibilities.

However all information again, greatly appreciated :wink:

If your data is fixed exactly like that, then:

$ cut -c17- file1 | paste - - - - 
00:24:00:2C:00:76 [mode 1, clkoffset 0x27bc]	Nokia Test 0	Phone, Cellular (0x5a0204)	
00:24:00:FB:00:9C [mode 1, clkoffset 0x3a75]	Nokia Test 1	Phone, Cellular (0x5a0204)	
6C:00:02:00:97:00 [mode 1, clkoffset 0x324a]	Nokia Test	Phone, Cellular (0x520204)
$
$
$ cat f18
BD Address:     00:24:00:2C:00:76 [mode 1, clkoffset 0x27bc]
Device name:    Nokia Test 0
Device class:   Phone, Cellular (0x5a0204)
BD Address:     00:24:00:FB:00:9C [mode 1, clkoffset 0x3a75]
Device name:    Nokia Test 1
Device class:   Phone, Cellular (0x5a0204)
BD Address:     6C:00:02:00:97:00 [mode 1, clkoffset 0x324a]
Device name:    Nokia Test
Device class:   Phone, Cellular (0x520204)
$
$ perl -ne 'if (/^.*:\s+(.*)$/){printf("%-20s  ",$1)} elsif(/^\s*$/) {print} END{print"\n"}' f18
00:24:00:2C:00:76 [mode 1, clkoffset 0x27bc]  Nokia Test 0          Phone, Cellular (0x5a0204)
00:24:00:FB:00:9C [mode 1, clkoffset 0x3a75]  Nokia Test 1          Phone, Cellular (0x5a0204)
6C:00:02:00:97:00 [mode 1, clkoffset 0x324a]  Nokia Test            Phone, Cellular (0x520204)
$
$

tyler_durden

1 Like

Holy cow gents !

Thanks for the great responses,

scottn, the results I am getting with the paste function seem to cut a few characters off, probably because the formatting is somewhat different with the real output.
But thanks, it has opened my eyes a bit more to the capabilities of paste !

tyler_durden,
Your response rocked it right on !

Awesome !

Thanks so much for your quick and professional responses.

tr "\n" "\t" < infile
$ ruby -rEnglish -00 -ne '$ORS="\n"; print if gsub(/\n|BD Address:\s+/,"");'  file
00:24:00:2C:00:76 [mode 1, clkoffset 0x27bc]Device name:    Nokia Test 0Device class:   Phone, Cellular (0x5a0204)
00:24:00:FB:00:9C [mode 1, clkoffset 0x3a75]Device name:    Nokia Test 1Device class:   Phone, Cellular (0x5a0204)
6C:00:02:00:97:00 [mode 1, clkoffset 0x324a]Device name:    Nokia TestDevice class:   Phone, Cellular (0x520204)