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

need script

Réponse
 
LinkBack Outils de la discussion
Vieux 24/03/2008, 18h08   #1
aixdude@yahoo.com
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut need script

only want to report first line, each time PNAM= value changes
second field delimited by | character
sample of source file

STAR=20080317 20:43:59|PNAM=ABSPC103
STAR=20080318 20:42:53|PNAM=ABSPC103
STAR=20080319 20:43:27|PNAM=ABSPC103
STAR=20080320 20:43:00|PNAM=ABSPC103
STAR=20080321 20:41:41|PNAM=ABSPC103
STAR=20080301 01:41:49|PNAM=ACFPC360
STAR=20080302 02:35:03|PNAM=ACFPC360
STAR=20080303 01:10:23|PNAM=ACFPC360
STAR=20080319 03:56:12|PNAM=EDIPP757
STAR=20080320 03:54:41|PNAM=EDIPP757
STAR=20080321 03:55:14|PNAM=EDIPP757
STAR=20080322 03:53:57|PNAM=EDIPP757
STAR=20080301 12:02:48|PNAM=HHRAC010
STAR=20080301 18:02:48|PNAM=HHRAC010
STAR=20080303 12:04:33|PNAM=HHRAC010

etc
  Réponse avec citation
Vieux 24/03/2008, 18h14   #2
Icarus Sparry
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut Re: need script

On Mon, 24 Mar 2008 10:08:24 -0700, aixdude@yahoo.com wrote:

> only want to report first line, each time PNAM= value changes second
> field delimited by | character sample of source file
>
> STAR=20080317 20:43:59|PNAM=ABSPC103
> STAR=20080318 20:42:53|PNAM=ABSPC103
> STAR=20080319 20:43:27|PNAM=ABSPC103
> STAR=20080320 20:43:00|PNAM=ABSPC103
> STAR=20080321 20:41:41|PNAM=ABSPC103
> STAR=20080301 01:41:49|PNAM=ACFPC360
> STAR=20080302 02:35:03|PNAM=ACFPC360
> STAR=20080303 01:10:23|PNAM=ACFPC360
> STAR=20080319 03:56:12|PNAM=EDIPP757
> STAR=20080320 03:54:41|PNAM=EDIPP757
> STAR=20080321 03:55:14|PNAM=EDIPP757
> STAR=20080322 03:53:57|PNAM=EDIPP757
> STAR=20080301 12:02:48|PNAM=HHRAC010
> STAR=20080301 18:02:48|PNAM=HHRAC010
> STAR=20080303 12:04:33|PNAM=HHRAC010
>
> etc


(untested)

awk -F\| '$2 != x { print $0; x=$2 ; }'
  Réponse avec citation
Vieux 24/03/2008, 18h30   #3
pk
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut Re: need script

aixdude@yahoo.com wrote:

> only want to report first line, each time PNAM= value changes
> second field delimited by | character
> sample of source file
>
> STAR=20080317 20:43:59|PNAM=ABSPC103
> STAR=20080318 20:42:53|PNAM=ABSPC103
> STAR=20080319 20:43:27|PNAM=ABSPC103
> STAR=20080320 20:43:00|PNAM=ABSPC103
> STAR=20080321 20:41:41|PNAM=ABSPC103
> STAR=20080301 01:41:49|PNAM=ACFPC360
> STAR=20080302 02:35:03|PNAM=ACFPC360
> STAR=20080303 01:10:23|PNAM=ACFPC360
> STAR=20080319 03:56:12|PNAM=EDIPP757
> STAR=20080320 03:54:41|PNAM=EDIPP757
> STAR=20080321 03:55:14|PNAM=EDIPP757
> STAR=20080322 03:53:57|PNAM=EDIPP757
> STAR=20080301 12:02:48|PNAM=HHRAC010
> STAR=20080301 18:02:48|PNAM=HHRAC010
> STAR=20080303 12:04:33|PNAM=HHRAC010


IIUC,

awk -F'=' '$NF!=pnam && pnam=$NF' file.txt

--
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 24/03/2008, 18h37   #4
Hermann Peifer
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut Re: need script

aixdude@yahoo.com wrote:
> only want to report first line, each time PNAM= value changes
> second field delimited by | character
> sample of source file
>
> STAR=20080317 20:43:59|PNAM=ABSPC103
> STAR=20080318 20:42:53|PNAM=ABSPC103
> STAR=20080319 20:43:27|PNAM=ABSPC103
> STAR=20080320 20:43:00|PNAM=ABSPC103
> STAR=20080321 20:41:41|PNAM=ABSPC103
> STAR=20080301 01:41:49|PNAM=ACFPC360
> STAR=20080302 02:35:03|PNAM=ACFPC360
> STAR=20080303 01:10:23|PNAM=ACFPC360
> STAR=20080319 03:56:12|PNAM=EDIPP757
> STAR=20080320 03:54:41|PNAM=EDIPP757
> STAR=20080321 03:55:14|PNAM=EDIPP757
> STAR=20080322 03:53:57|PNAM=EDIPP757
> STAR=20080301 12:02:48|PNAM=HHRAC010
> STAR=20080301 18:02:48|PNAM=HHRAC010
> STAR=20080303 12:04:33|PNAM=HHRAC010
>
> etc


Yet another option:

awk -F= '!a[$NF]++'

Hermann
  Réponse avec citation
Vieux 25/03/2008, 14h36   #5
aixdude@yahoo.com
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut Re: need script

On Mar 24, 1:08pm, "aixd...@yahoo.com" <aixd...@yahoo.com> wrote:
> only want to report first line, each time PNAM= value changes
> second field delimited by | character
> sample of source file
>
> STAR=20080317 20:43:59|PNAM=ABSPC103
> STAR=20080318 20:42:53|PNAM=ABSPC103
> STAR=20080319 20:43:27|PNAM=ABSPC103
> STAR=20080320 20:43:00|PNAM=ABSPC103
> STAR=20080321 20:41:41|PNAM=ABSPC103
> STAR=20080301 01:41:49|PNAM=ACFPC360
> STAR=20080302 02:35:03|PNAM=ACFPC360
> STAR=20080303 01:10:23|PNAM=ACFPC360
> STAR=20080319 03:56:12|PNAM=EDIPP757
> STAR=20080320 03:54:41|PNAM=EDIPP757
> STAR=20080321 03:55:14|PNAM=EDIPP757
> STAR=20080322 03:53:57|PNAM=EDIPP757
> STAR=20080301 12:02:48|PNAM=HHRAC010
> STAR=20080301 18:02:48|PNAM=HHRAC010
> STAR=20080303 12:04:33|PNAM=HHRAC010
>
> etc


I would also like to grab fields starting with SFIL= and DFIL=
however these fields are NOT consistently in the same field position
of every line

thanks in advance
  Réponse avec citation
Vieux 25/03/2008, 15h09   #6
pk
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut Re: need script

aixdude@yahoo.com wrote:

> On Mar 24, 1:08Âpm, "aixd...@yahoo.com" <aixd...@yahoo.com> wrote:
>> only want to report first line, each time ÂPNAM= value changes
>> second field delimited by | character
>> sample of source file
>>
>> STAR=20080317 20:43:59|PNAM=ABSPC103
>> STAR=20080318 20:42:53|PNAM=ABSPC103
>> STAR=20080319 20:43:27|PNAM=ABSPC103
>> STAR=20080320 20:43:00|PNAM=ABSPC103
>> STAR=20080321 20:41:41|PNAM=ABSPC103
>> STAR=20080301 01:41:49|PNAM=ACFPC360
>> STAR=20080302 02:35:03|PNAM=ACFPC360
>> STAR=20080303 01:10:23|PNAM=ACFPC360
>> STAR=20080319 03:56:12|PNAM=EDIPP757
>> STAR=20080320 03:54:41|PNAM=EDIPP757
>> STAR=20080321 03:55:14|PNAM=EDIPP757
>> STAR=20080322 03:53:57|PNAM=EDIPP757
>> STAR=20080301 12:02:48|PNAM=HHRAC010
>> STAR=20080301 18:02:48|PNAM=HHRAC010
>> STAR=20080303 12:04:33|PNAM=HHRAC010
>>
>> etc

>
> I would also like to grab fields starting with SFIL= and DFIL=
> however these fields are NOT consistently in the same field position
> of every line


Provide sample input and expected output.

--
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 25/03/2008, 15h40   #7
aixdude@yahoo.com
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut Re: need script

On Mar 25, 10:09am, pk <p...@pk.invalid> wrote:
> aixd...@yahoo.com wrote:
> > On Mar 24, 1:08pm, "aixd...@yahoo.com" <aixd...@yahoo.com> wrote:
> >> only want to report first line, each time PNAM= value changes
> >> second field delimited by | character
> >> sample of source file

>
> >> STAR=20080317 20:43:59|PNAM=ABSPC103
> >> STAR=20080318 20:42:53|PNAM=ABSPC103
> >> STAR=20080319 20:43:27|PNAM=ABSPC103
> >> STAR=20080320 20:43:00|PNAM=ABSPC103
> >> STAR=20080321 20:41:41|PNAM=ABSPC103
> >> STAR=20080301 01:41:49|PNAM=ACFPC360
> >> STAR=20080302 02:35:03|PNAM=ACFPC360
> >> STAR=20080303 01:10:23|PNAM=ACFPC360
> >> STAR=20080319 03:56:12|PNAM=EDIPP757
> >> STAR=20080320 03:54:41|PNAM=EDIPP757
> >> STAR=20080321 03:55:14|PNAM=EDIPP757
> >> STAR=20080322 03:53:57|PNAM=EDIPP757
> >> STAR=20080301 12:02:48|PNAM=HHRAC010
> >> STAR=20080301 18:02:48|PNAM=HHRAC010
> >> STAR=20080303 12:04:33|PNAM=HHRAC010

>
> >> etc

>
> > I would also like to grab fields starting with SFIL= and DFIL=
> > however these fields are NOT consistently in the same field position
> > of every line

>
> Provide sample input and expected output.
>
> --
> 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.- Hide quoted text -
>
> - Show quoted text -


input file looks like

STAR=20080320 17:00:51|PNAM=SRCP|RSTR=N|SFIL=SRCPPPB|SBYX=252685 |DFIL=/
connect2/filea
STAR=20080301 00:48:22|PNAM=TAGP|SFIL=TAGPFPB|SFSZ=55800|DFIL=/ndm/hil/
fileb|DBYW=25425
STAR=20080301 00:48:16|PNAM=TAGP|SFIL=TAGPFPC|SFSZ=27900|DFIL=/ndm/hil/
filecl|DBYW=500
STAR=20080303 11:04:43|PNAM=TELP|RSTR=N|SFIL=TELPCPB|SBYX=1134|D FIL=/
ndm/hil/filee

want output to be

field 1 STAR=
fileld 2 PNAM=
field 3 SFIL=
filed 4 DFIL=

don't care about other items


  Réponse avec citation
Vieux 25/03/2008, 15h54   #8
aixdude@yahoo.com
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut Re: need script

On Mar 25, 10:40am, "aixd...@yahoo.com" <aixd...@yahoo.com> wrote:
> On Mar 25, 10:09am, pk <p...@pk.invalid> wrote:
>
>
>
>
>
> > aixd...@yahoo.com wrote:
> > > On Mar 24, 1:08pm, "aixd...@yahoo.com" <aixd...@yahoo.com> wrote:
> > >> only want to report first line, each time PNAM= value changes
> > >> second field delimited by | character
> > >> sample of source file

>
> > >> STAR=20080317 20:43:59|PNAM=ABSPC103
> > >> STAR=20080318 20:42:53|PNAM=ABSPC103
> > >> STAR=20080319 20:43:27|PNAM=ABSPC103
> > >> STAR=20080320 20:43:00|PNAM=ABSPC103
> > >> STAR=20080321 20:41:41|PNAM=ABSPC103
> > >> STAR=20080301 01:41:49|PNAM=ACFPC360
> > >> STAR=20080302 02:35:03|PNAM=ACFPC360
> > >> STAR=20080303 01:10:23|PNAM=ACFPC360
> > >> STAR=20080319 03:56:12|PNAM=EDIPP757
> > >> STAR=20080320 03:54:41|PNAM=EDIPP757
> > >> STAR=20080321 03:55:14|PNAM=EDIPP757
> > >> STAR=20080322 03:53:57|PNAM=EDIPP757
> > >> STAR=20080301 12:02:48|PNAM=HHRAC010
> > >> STAR=20080301 18:02:48|PNAM=HHRAC010
> > >> STAR=20080303 12:04:33|PNAM=HHRAC010

>
> > >> etc

>
> > > I would also like to grab fields starting with SFIL= and DFIL=
> > > however these fields are NOT consistently in the same field position
> > > of every line

>
> > Provide sample input and expected output.

>
> > --
> > 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.- Hide quoted text -

>
> > - Show quoted text -

>
> input file looks like
>
> STAR=20080320 17:00:51|PNAM=SRCP|RSTR=N|SFIL=SRCPPPB|SBYX=252685 |DFIL=/
> connect2/filea
> STAR=20080301 00:48:22|PNAM=TAGP|SFIL=TAGPFPB|SFSZ=55800|DFIL=/ndm/hil/
> fileb|DBYW=25425
> STAR=20080301 00:48:16|PNAM=TAGP|SFIL=TAGPFPC|SFSZ=27900|DFIL=/ndm/hil/
> filecl|DBYW=500
> STAR=20080303 11:04:43|PNAM=TELP|RSTR=N|SFIL=TELPCPB|SBYX=1134|D FIL=/
> ndm/hil/filee
>
> want output to be
>
> field 1 STAR=
> fileld 2 PNAM=
> field 3 SFIL=
> filed 4 DFIL=
>
> don't care about other items- Hide quoted text -
>
> - Show quoted text -


actually output to be exact, should look like this for each line

STAR=data|PNAM=data|SFIL=data|DFIL=data

  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 02h34.


É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
Ad Management by RedTyger
©Tous droits réservés par les parties respectives
Page generated in 0,16798 seconds with 16 queries