oppsite of paste

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
Florian Kaufmann [ Di, 13 November 2007 18:46 ] [ ID #1869029 ]

Re: oppsite of paste

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.
<snip>

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.
Ed Morton [ Di, 13 November 2007 18:53 ] [ ID #1869031 ]

Re: oppsite of paste

On 2007-11-13, Florian Kaufmann <sensorflo [at] gmail.com> 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.
Claudio [ Di, 13 November 2007 21:05 ] [ ID #1869033 ]

Re: oppsite of paste

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 [at] {$x[$_]},shift [at] F for 0..$#F}{print for
map [at] $_, [at] x'
a
b
c
d
e
f
g
h
i



John
--
use Perl;
program
fulfillment
krahnj [ Di, 13 November 2007 23:50 ] [ ID #1869038 ]

Re: oppsite of paste

Florian Kaufmann <sensor... [at] gmail.com> 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
brian_hiles [ Mi, 14 November 2007 03:09 ] [ ID #1869952 ]
Linux » comp.unix.shell » oppsite of paste

Vorheriges Thema: Exclude directory in recursive copy
Nächstes Thema: capturing a return code