sed Replace

I have a file whose output words are always like this:

aaaa
bbbb
cccc
dddd

. Trying to arrange the data so that there are 2 columns such that the 1st word become the 1st column like this:

aaaa aaaa
              aaaa bbbb
              aaaa cccc
              aaaa dddd

Trying to use awk and sed but I'm confusing myself and can't get anywhere. Any help would greatly be appreciated. Thanks.

What have you tried with awk?

This is getting me close but still no go

 awk 'NF==2{x=$1}NF==2{$1=x;print}' file
awk 'BEGIN { getline col<"inputFile"  } ; { print col " " $1 }' inputFile

that's just giving an error geeky

Not sure how serious you are about the indentation of lines 2+ in your sample output? Try

awk 'NR==1 {T=$1} {print T, $0}' file
aaaa aaaa
aaaa bbbb
aaaa cccc
aaaa dddd

Don't remove the "" in

getline col<"inputFile"

it should works

oh wow, nicely done Rudi thank you!

If file contains:

aaaa
bbbb
cccc
dddd

as shown in your 1st message in this thread. NF==2 will be false for every input line (since there is only one field on each input line) and no output would be produced.

If you were serious about the leading spaces except on the first output line, I think you want something like:

awk '
NR == 1 { x = $1 }
{ printf("%s%s %s\n", NR == 1 ? "" : "              ", x, $1) }' file

As always, if you want to try this on a Solaris/SunOS system, change awk to /usr/xpg4/bin/awk , /usr/xpg6/bin/awk , or nawk .