PHWinfo banniere

Titres
PORTAIL ANNUAIRE ARTICLES COMPARATEUR HÉBERGEURS DEVIS FORUMS RÉDUCTEUR D'URL
Précédent   PHWinfo > Forums Hébergement > Forum Serveur - Sécurité et techniques > comp.unix.shell > oppsite of paste
S'inscrire FAQ Membres Recherche Messages du jour Marquer les forums comme lus
comp.unix.shell Using and programming the Unix shell.

oppsite of paste

Réponse
 
LinkBack Outils de la discussion
Vieux 13/11/2007, 17h46   #1
Florian Kaufmann
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut 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

  Réponse avec citation
Vieux 13/11/2007, 17h53   #2
Ed Morton
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut 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.

  Réponse avec citation
Vieux 13/11/2007, 20h05   #3
Claudio
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut Re: oppsite of paste

On 2007-11-13, Florian Kaufmann <sensorflo@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.

  Réponse avec citation
Vieux 13/11/2007, 22h50   #4
John W. Krahn
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut 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@{$x[$_]},shift@F for 0..$#F}{print for
map@$_,@x'
a
b
c
d
e
f
g
h
i



John
--
use Perl;
program
fulfillment
  Réponse avec citation
Vieux 14/11/2007, 02h09   #5
bsh
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut Re: oppsite of paste

Florian Kaufmann <sensor...@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

  Réponse avec citation
Réponse


Outils de la discussion

Règles de messages
Vous ne pouvez pas créer de nouvelles discussions
Vous ne pouvez pas envoyer des réponses
Vous ne pouvez pas envoyer des pièces jointes
Vous ne pouvez pas modifier vos messages

Les balises BB sont activées : oui
Les smileys sont activés : oui
La balise [IMG] est activée : oui
Le code HTML peut être employé : non
Trackbacks are oui
Pingbacks are oui
Refbacks are oui


Fuseau horaire GMT +1. Il est actuellement 09h56.


Édité par : vBulletin® version 3.7.2
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Search Engine Friendly URLs by vBSEO 3.2.0 RC5 Tous droits réservés.
Version française #16 par l'association vBulletin francophone
PHWinfo est un site Éducation Sans Frontières
Ad Management by RedTyger
©Tous droits réservés par les parties respectives
Page generated in 0,10091 seconds with 13 queries