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 > display in a tree structure
S'inscrire FAQ Membres Recherche Messages du jour Marquer les forums comme lus
comp.unix.shell Using and programming the Unix shell.

display in a tree structure

Réponse
 
LinkBack Outils de la discussion
Vieux 26/03/2008, 12h06   #1
Vakayil Thobias
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut display in a tree structure


I have to display the data from a file in tree structure(ksh).
The file format is as follows(first field parent, second field child) :

PM01 PM02
PM01 PM1A
PM02 PM03
PM03 PM04
PM04 PM05
PM04 PM06
PM1A PM1B
PM1A PM1C

The output should be like this :
PM01 -- PM02 -- PM03 -- PM04 -- PM05
PM06
PM01 PM1A -- PM1B
PM1C

Anybody have idea ?

Regards,
Thobias


  Réponse avec citation
Vieux 26/03/2008, 13h12   #2
muhammadshoaibhasan@gmail.com
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut Re: display in a tree structure

dear, u can have this out of display by having a simple bash script.

On Mar 26, 4:06pm, "Vakayil Thobias" <vakayil.thob...@alcatel-
lucent.com> wrote:
> I have to display the data from a file in tree structure(ksh).
> The file format is as follows(first field parent, second field child) :
>
> PM01 PM02
> PM01 PM1A
> PM02 PM03
> PM03 PM04
> PM04 PM05
> PM04 PM06
> PM1A PM1B
> PM1A PM1C
>
> The output should be like this :
> PM01 -- PM02 -- PM03 -- PM04 -- PM05
> PM06
> PM01 PM1A -- PM1B
> PM1C
>
> Anybody have idea ?
>
> Regards,
> Thobias


  Réponse avec citation
Vieux 26/03/2008, 14h53   #3
Janis Papanagnou
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut Re: display in a tree structure

Vakayil Thobias wrote:
> I have to display the data from a file in tree structure(ksh).
> The file format is as follows(first field parent, second field child) :
>
> PM01 PM02
> PM01 PM1A
> PM02 PM03
> PM03 PM04
> PM04 PM05
> PM04 PM06
> PM1A PM1B
> PM1A PM1C
>
> The output should be like this :
> PM01 -- PM02 -- PM03 -- PM04 -- PM05
> PM06
> PM01 PM1A -- PM1B
> PM1C
>


The above "output" doesn't seem to have a structure that is
anyhow related to a tree.

> Anybody have idea ?
>
> Regards,
> Thobias
>
>

  Réponse avec citation
Vieux 26/03/2008, 15h14   #4
pk
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut Re: display in a tree structure

Janis Papanagnou wrote:

> Vakayil Thobias wrote:
>> I have to display the data from a file in tree structure(ksh).
>> The file format is as follows(first field parent, second field child) :
>>
>> PM01 PM02
>> PM01 PM1A
>> PM02 PM03
>> PM03 PM04
>> PM04 PM05
>> PM04 PM06
>> PM1A PM1B
>> PM1A PM1C
>>
>> The output should be like this :
>> PM01 -- PM02 -- PM03 -- PM04 -- PM05
>> PM06
>> PM01 PM1A -- PM1B
>> PM1C
>>

>
> The above "output" doesn't seem to have a structure that is
> anyhow related to a tree.


I think that should have been perhaps

PM01 -- PM02 -- PM03 -- PM04 -- PM05
+ -- PM06

PM01 -- PM1A -- PM1B
+ -- PM1C

Or some variation thereof.

--
All the commands are tested with bash and GNU tools, so they may use
nonstandard features. I try to mention when something is nonstandard (if
I'm aware of that), but I may miss something. Corrections are welcome.
  Réponse avec citation
Vieux 26/03/2008, 15h38   #5
Ed Morton
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut Re: display in a tree structure

On 3/26/2008 6:06 AM, Vakayil Thobias wrote:
> I have to display the data from a file in tree structure(ksh).
> The file format is as follows(first field parent, second field child) :
>
> PM01 PM02
> PM01 PM1A
> PM02 PM03
> PM03 PM04
> PM04 PM05
> PM04 PM06
> PM1A PM1B
> PM1A PM1C
>
> The output should be like this :
> PM01 -- PM02 -- PM03 -- PM04 -- PM05
> PM06
> PM01 PM1A -- PM1B
> PM1C
>
> Anybody have idea ?


Here's a start:

$ cat file
PM01 PM02
PM01 PM1A
PM02 PM03
PM03 PM04
PM04 PM05
PM04 PM06
PM1A PM1B
PM1A PM1C

$ cat dt.awk
function descend(indent,branch, child,childA) {
printf "%"indent++"s%s\n","",branch
split(children[branch],childA)
for (child in childA)
descend(indent,childA[child])
}
{
branches[$1]
branches[$2]
children[$1] = children[$1] FS $2
parent[$2] = $1
}
END {
for (branch in branches)
if (!(branch in parent)) {
descend(0,branch)
delete branches[branch]
}
print "-----"
for (branch in branches)
descend(0,branch)
}

$ awk -f dt.awk file
PM01
PM02
PM03
PM04
PM05
PM06
PM1A
PM1B
PM1C
-----
PM05
PM1A
PM1B
PM1C
PM1B
PM06
PM1C
PM02
PM03
PM04
PM05
PM06
PM03
PM04
PM05
PM06
PM04
PM05
PM06

Regards,

Ed.


  Réponse avec citation
Vieux 27/03/2008, 02h35   #6
bsh
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut Re: display in a tree structure

"Janis Papanagnou" <Janis_Papanag...@hotmail.com> wrote:
> Vakayil Thobias wrote:
> > ...

> The above "output" doesn't seem to have a structure that is
> anyhow related to a tree.


Indeed. How can we appropriately answer to your issue if it is
not well formed? "A problem, properly stated, is a problem on it's way
to being solved" -- Buckminster Fuller

That being said, your problem looks a lot like an application
of tsort (RTFM) and some awk/sed post-processing.

Or, just maybe:

"decision_tree_hierarchy.c++"
http://atlas.kennesaw.edu/~rbentley/...erarchy.tar.gz

If we're solving a homework problem, presumably the former
avenue of approach will do best.

=Brian
  Réponse avec citation
Vieux 27/03/2008, 05h20   #7
Vakayil Thobias
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut Re: display in a tree structure


"Ed Morton" <morton@lsupcaemnt.com> wrote in message
news:47EA5FE9.5000800@lsupcaemnt.com...
> On 3/26/2008 6:06 AM, Vakayil Thobias wrote:
>> I have to display the data from a file in tree structure(ksh).
>> The file format is as follows(first field parent, second field child) :
>>
>> PM01 PM02
>> PM01 PM1A
>> PM02 PM03
>> PM03 PM04
>> PM04 PM05
>> PM04 PM06
>> PM1A PM1B
>> PM1A PM1C
>>
>> The output should be like this :
>> PM01 -- PM02 -- PM03 -- PM04 -- PM05
>> PM06
>> PM01 PM1A -- PM1B
>> PM1C
>>
>> Anybody have idea ?

>
> Here's a start:
>
> $ cat file
> PM01 PM02
> PM01 PM1A
> PM02 PM03
> PM03 PM04
> PM04 PM05
> PM04 PM06
> PM1A PM1B
> PM1A PM1C
>
> $ cat dt.awk
> function descend(indent,branch, child,childA) {
> printf "%"indent++"s%s\n","",branch
> split(children[branch],childA)
> for (child in childA)
> descend(indent,childA[child])
> }
> {
> branches[$1]
> branches[$2]
> children[$1] = children[$1] FS $2
> parent[$2] = $1
> }
> END {
> for (branch in branches)
> if (!(branch in parent)) {
> descend(0,branch)
> delete branches[branch]
> }
> print "-----"
> for (branch in branches)
> descend(0,branch)
> }
>
> $ awk -f dt.awk file
> PM01
> PM02
> PM03
> PM04
> PM05
> PM06
> PM1A
> PM1B
> PM1C
> -----
> PM05
> PM1A
> PM1B
> PM1C
> PM1B
> PM06
> PM1C
> PM02
> PM03
> PM04
> PM05
> PM06
> PM03
> PM04
> PM05
> PM06
> PM04
> PM05
> PM06
>
> Regards,
>
> Ed.
>
>


Hello Ed Morton,

Thanks for your reply. It's working fine.
Great work.

Regards,
Thobias


  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 20h59.


Édité par : vBulletin® version 3.7.3
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 ©2000-2008
Ad Management by RedTyger
©Tous droits réservés par les parties respectives
Page generated in 0,16056 seconds with 15 queries