oppsite of paste

oppsite of paste

am 13.11.2007 18:46:55 von Florian Kaufmann

Hello

I am searching something like the opposite of paste. I know that cut
is somehow the opposite. But say I have

$ cat myfile
a d g
b e h
c f i

and what I want to get out of the file myfile is this
a
b
c
d
e
f
g
h
i

That is put all columns after each other.

I really don't see how I can achieve that with cut. I can think of
$ cut -f 1,2,3 -d \ myfile --output-delimiter $'\n'
a
d
g
b
e
h
c
f
i

But that gives not the result I am searching for.

Any ideas?

Greetings

Flo

Re: oppsite of paste

am 13.11.2007 18:53:57 von Ed Morton

On 11/13/2007 11:46 AM, Florian Kaufmann wrote:
> Hello
>
> I am searching something like the opposite of paste. I know that cut
> is somehow the opposite. But say I have
>
> $ cat myfile
> a d g
> b e h
> c f i
>
> and what I want to get out of the file myfile is this
> a
> b
> c
> d
> e
> f
> g
> h
> i
>
> That is put all columns after each other.


Try this:

awk '{ for (fld=1;fld<=NF;fld++)
a[NR,fld] = $fld
}
END{ for (fld=1;fld<=NF;fld++)
for (rec=1;rec<=NR;rec++)
print a[rec,fld]
}' file

Regards,

Ed.

Re: oppsite of paste

am 13.11.2007 21:05:40 von Claudio

On 2007-11-13, Florian Kaufmann wrote:
> Hello
>
> I am searching something like the opposite of paste. I know that cut
> is somehow the opposite. But say I have
>
> $ cat myfile
> a d g
> b e h
> c f i
>
> and what I want to get out of the file myfile is this
> a
> b
> c
> d
> e
> f
> g
> h
> i

Maybe?

for i in 1 2 3; do cut -d\ -f $i myfile ; done

Best Regards,
Claudio.

Re: oppsite of paste

am 13.11.2007 23:50:29 von krahnj

Florian Kaufmann wrote:
>
> I am searching something like the opposite of paste. I know that cut
> is somehow the opposite. But say I have
>
> $ cat myfile
> a d g
> b e h
> c f i
>
> and what I want to get out of the file myfile is this
> a
> b
> c
> d
> e
> f
> g
> h
> i

$ echo "a d g
b e h
c f i" | perl -lane'push@{$x[$_]},shift@F for 0..$#F}{print for
map@$_,@x'
a
b
c
d
e
f
g
h
i



John
--
use Perl;
program
fulfillment

Re: oppsite of paste

am 14.11.2007 03:09:00 von brian_hiles

Florian Kaufmann wrote:
> Any ideas?

It looks like -- and you do not make clear -- that you
are _either_ doing a sort:

sed -e 's/ /\
/g' myfile | sort # YASS: Yet Another Sed(1) Solution

.... or an idempotent decomposition of the transpose of
the matrix (laying the matrix on its side and enumerating
the elements) -- which is Ed Morton's awk(1) solution.

=Brian