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 > extract info from a file and put it in several files
S'inscrire FAQ Membres Recherche Messages du jour Marquer les forums comme lus
comp.unix.shell Using and programming the Unix shell.

extract info from a file and put it in several files

Réponse
 
LinkBack Outils de la discussion
Vieux 03/09/2007, 12h34   #1
gniagnia
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut extract info from a file and put it in several files

Hi all,

The following file lists all disks from a diskbay...and is sorted by
disk capacity (first the 146 Go disks, then the 300 Go ones) :

objecttype = Disk 146 Go
objectname = Disk003

objecttype = Disk 146 Go
objectname = Disk005

objecttype = Disk 146 Go
objectname = Disk008

objecttype = Disk 300 Go
objectname = Disk004

objecttype = Disk 300 Go
objectname = Disk016

objecttype = Disk 300 Go
objectname = Disk022

objecttype = Disk 300 Go
objectname = Disk030

etc...


I'd like to write a script that would create 2 files : one containing
the 146 Go disks info, and the other with the 300 Go):

file1 :

objecttype = Disk 146 Go
objectname = Disk003

objecttype = Disk 146 Go
objectname = Disk005

objecttype = Disk 146 Go
objectname = Disk008



file2 :

objecttype = Disk 300 Go
objectname = Disk004

objecttype = Disk 300 Go
objectname = Disk016

objecttype = Disk 300 Go
objectname = Disk022

objecttype = Disk 300 Go
objectname = Disk030



What would be the simplest way to do this?

thanks for your in advance.

  Réponse avec citation
Vieux 03/09/2007, 13h15   #2
Ed Morton
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut Re: extract info from a file and put it in several files

gniagnia wrote:
> Hi all,
>
> The following file lists all disks from a diskbay...and is sorted by
> disk capacity (first the 146 Go disks, then the 300 Go ones) :
>
> objecttype = Disk 146 Go
> objectname = Disk003
>
> objecttype = Disk 146 Go
> objectname = Disk005
>
> objecttype = Disk 146 Go
> objectname = Disk008
>
> objecttype = Disk 300 Go
> objectname = Disk004
>
> objecttype = Disk 300 Go
> objectname = Disk016
>
> objecttype = Disk 300 Go
> objectname = Disk022
>
> objecttype = Disk 300 Go
> objectname = Disk030
>
> etc...
>
>
> I'd like to write a script that would create 2 files : one containing
> the 146 Go disks info, and the other with the 300 Go):
>
> file1 :
>
> objecttype = Disk 146 Go
> objectname = Disk003
>
> objecttype = Disk 146 Go
> objectname = Disk005
>
> objecttype = Disk 146 Go
> objectname = Disk008
>
>
>
> file2 :
>
> objecttype = Disk 300 Go
> objectname = Disk004
>
> objecttype = Disk 300 Go
> objectname = Disk016
>
> objecttype = Disk 300 Go
> objectname = Disk022
>
> objecttype = Disk 300 Go
> objectname = Disk030
>
>
>
> What would be the simplest way to do this?
>
> thanks for your in advance.
>


awk -v RS= '{print > "file"$4}' file

Ed.
  Réponse avec citation
Vieux 03/09/2007, 18h37   #3
gniagnia
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut Re: extract info from a file and put it in several files


> awk -v RS= '{print > "file"$4}' file
>
> Ed.


thx a lot !
But, actually ... my file is a bit more talkative than what i said...
Here is a real sample of the file i want to process :


\Disk Groups\Disk 146 Go\Disk 002 information:
object
objectid .............................:
12080710110000201648B9C60000000000000000
objectname ...........................: \Disk Groups\Disk 146 Go
\Disk 002
objecttype ...........................: disk
objectwwn ............................:
objecthexuid .........................: 2000-0011-
c6b9-4816-0000-0000-0000-0000
diskname .............................: Disk 002
uid ..................................:
2066.7.16.536870929.3334031382.0.0
operationalstate .....................: good
operationalstatedetail ...............: member_ok
objectparentuid ......................:
256.7.16.1610942644.1070310.24576.262144
loopalpa .........................: 2b
loopposition .....................: 48
loop
loopname .........................: loopb
portwwid .........................: 2000-0011-C6B9-4816
loopid ...........................: 107
assignedlun ......................: 0
loopstate ........................: good
loopalpa .........................: 2b
loopposition .....................: 10
formattedcapacity ....................: 286749488
diskdrivetype ........................: online
actualusage ..........................: grouped
requestedusage .......................: grouped
quorumdisk ...........................: no
diskgroupname ........................: Disk 146 Go
diskgroupid ..........................:
00010710B4080560E65410000060000000000400
diskbaynumber ........................: 10
looppair .............................: looppair1
shelfnumber ..........................: 1
DiskCanCodeLoad ......................: 0

\Disk Groups\Disk 146 Go\Disk 003 information:
object
objectid .............................:
12080710110000201648B9C60000000000000000
objectname ...........................: \Disk Groups\Disk 146 Go
\Disk 002
objecttype ...........................: disk
objectwwn ............................:
objecthexuid .........................: 2000-0011-
c6b9-4816-0000-0000-0000-0000
diskname .............................: Disk 003
uid ..................................:
2066.7.16.536870929.3334031382.0.0
operationalstate .....................: good
operationalstatedetail ...............: member_ok
objectparentuid ......................:
256.7.16.1610942644.1070310.24576.262144
loopalpa .........................: 2b
loopposition .....................: 48
loop
loopname .........................: loopb
portwwid .........................: 2000-0011-C6B9-4816
loopid ...........................: 107
assignedlun ......................: 0
loopstate ........................: good
loopalpa .........................: 2b
loopposition .....................: 10
formattedcapacity ....................: 286749488
diskdrivetype ........................: online
actualusage ..........................: grouped
requestedusage .......................: grouped
quorumdisk ...........................: no
diskgroupname ........................: Disk 146 Go
diskgroupid ..........................:
00010710B4080560E65410000060000000000400
diskbaynumber ........................: 10
looppair .............................: looppair1
shelfnumber ..........................: 1
DiskCanCodeLoad ......................: 0

\Disk Groups\Disk 300 Go\Disk 001 information:
object
objectid .............................:
12080710110000201648B9C60000000000000000
objectname ...........................: \Disk Groups\Disk 300 Go
\Disk 001
objecttype ...........................: disk
objectwwn ............................:
objecthexuid .........................: 2000-0011-
c6b9-4816-0000-0000-0000-0000
diskname .............................: Disk 001
uid ..................................:
2066.7.16.536870929.3334031382.0.0
operationalstate .....................: good
operationalstatedetail ...............: member_ok
objectparentuid ......................:
256.7.16.1610942644.1070310.24576.262144
loopalpa .........................: 2b
loopposition .....................: 48
loop
loopname .........................: loopb
portwwid .........................: 2000-0011-C6B9-4816
loopid ...........................: 107
assignedlun ......................: 0
loopstate ........................: good
loopalpa .........................: 2b
loopposition .....................: 10
formattedcapacity ....................: 286749488
diskdrivetype ........................: online
actualusage ..........................: grouped
requestedusage .......................: grouped
quorumdisk ...........................: no
diskgroupname ........................: Disk 300 Go
diskgroupid ..........................:
00010710B4080560E65410000060000000000400
diskbaynumber ........................: 10
looppair .............................: looppair1
shelfnumber ..........................: 1
DiskCanCodeLoad ......................: 0


i try to fill one file with the 2 first disks details (146 Go),
another one with the 300 go disks details....but I am such a noob that
i cannot adapt your script with it.




  Réponse avec citation
Vieux 03/09/2007, 20h14   #4
Ed Morton
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut Re: extract info from a file and put it in several files

gniagnia wrote:

>>awk -v RS= '{print > "file"$4}' file
>>
>> Ed.

>
>
> thx a lot !
> But, actually ... my file is a bit more talkative than what i said...
> Here is a real sample of the file i want to process :
>
>
> \Disk Groups\Disk 146 Go\Disk 002 information:

<snip>

Just use $3 instead of $4.

Ed.
  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 06h04.


É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,15970 seconds with 12 queries