|
|
|
|
||||||
| comp.unix.shell Using and programming the Unix shell. |
![]() |
|
|
LinkBack | Outils de la discussion |
|
|
#1 |
|
Messages: n/a
Hébergeur: |
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 |
|
|
|
#2 |
|
Messages: n/a
Hébergeur: |
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 ; }' |
|
|
|
#3 |
|
Messages: n/a
Hébergeur: |
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. |
|
|
|
#4 |
|
Messages: n/a
Hébergeur: |
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 |
|
|
|
#5 |
|
Messages: n/a
Hébergeur: |
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 |
|
|
|
#6 |
|
Messages: n/a
Hébergeur: |
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. |
|
|
|
#7 |
|
Messages: n/a
Hébergeur: |
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 |
|
|
|
#8 |
|
Messages: n/a
Hébergeur: |
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 |
|
![]() |
| Outils de la discussion | |
|
|