3

note I'm a beginner with SED.

We make use of sed-command which looks in the output of a clearcase command and obtains the names of users with a view:

<clearcase output> | sed -n "/Development streams:/,// s/[^ ]* *Views: *\([^_ ]*\)_.*/\1/p"

(Example clearcase output:

Project:              project:xx0.0_xx0000@/xxxx/xxxxx_xxxxxxxx0
Project's mastership: XXXXXXXXX@/xxxx/xxxxx_xxxxxxxx0
Project folder:       folder:XX0.0@/xxxx/xxxxx_xxxxxxxx0 (RootFolder/Xxxxxxxx/XX0.0)
Modifiable components:component:00000000000@/xxxx/xxxxxx_xxxxxxxx0
                      component:xxxxxxx_xxxxxxx@/xxxx/xxxxxx_xxxxxxxx0
                      component:xxxxxxxxxxxxxx_x@/xxxx/xxxxxx_xxxxxxxx0
                      component:xxxxx@/xxxx/xxxxxx_xxxxxxxx0
                      component:xxxxxx_xxxxxxxxxxx@/xxxx/xxxxxx_xxxxxxxx0

Integration stream:   stream:xx0.0_xx0000_integration@/xxxx/xxxxx_xxxxxxxx0 (FI: nemelis)
Integration views:    olduser_xx0.0_xx0000_int - Properties: dynamic ucmview readwrite nshareable_dos
                      nemelis_xx0.0_xx0000_int - Properties: dynamic ucmview readwrite nshareable_dos
                      otheruser_xx0.0_xx0000_int - Properties: dynamic ucmview readwrite nshareable_dos

Development streams:  stream:nemelis_xx0.0_xx0000@/xxxx/xxxxx_xxxxxxxx0 [unlocked] - No rebase or delivery is pending.
                       Views:nemelis_xx0.0_xx0000
                      stream:otheruser_xx0.0_xx0000_streamidentifier@/xxxx/xxxxx_xxxxxxxx0 [unlocked] - No rebase or delivery is pending.
                       Views:otheruser_xx0.0_xx0000_streamidentifier

)

On Solaris it will output:

nemelis

otheruser

But on (Redhat-)Linux only the first name is given.

(Note: I've looked on Stackoverflow and found comments that Sed is always greedy on Posix / Gnu and that Perl should be used (see Non greedy regex matching in sed?). Thus I've tried to fix it with Perl, but than I ran into a forrest of problems with the p at the end, using "//", "|", missing operator before < token >, etcetera, hence my post here)

Community
  • 1
  • 1
Nemelis
  • 4,858
  • 2
  • 17
  • 37
  • It doesn't answer your question, but you could give ssed (super-sed) a try. https://launchpad.net/ssed/ – stuXnet Apr 25 '14 at 09:29
  • In the range expression the second part of the range uses the empty regexp. The empty regexp uses the last matched regexp in this case the regexp from the substitute command. As the substitute command is true in the case of the first user the range expression thereafter is toggled and the remaining user is not seen as it is out of the range. If the range was supposed to be the first regexp repeated then the second part of the range should be explicit. An example test is `seq 30|sed -n '/5/,//{s/6/&X/;p}'` – potong Apr 25 '14 at 10:44

1 Answers1

2

Not sure what you're trying to achieve by specifying the address as //. You probably imply that it should be end of file or a blank line. Use $ as the address in the former case, and /^$/ in the latter.

The following might work for you:

sed -n "/Development streams:/,$ s/[^ ]* *Views: *\([^_ ]*\)_.*/\1/p"

From the manual:

$

 This address matches the last line of the last file of input, or
 the last line of each file when the `-i' or `-s' options are
 specified.
devnull
  • 118,548
  • 33
  • 236
  • 227
  • It was an existing script, so I do not know why the `//` is in. But your suggestion works both on Solaris and Linux. Thanx – Nemelis Apr 25 '14 at 10:43