hi
another data parsing question. I work on a mac and try to analyse my group IDs

$ sudo dscl . list groups gid
...
_amavisd 83
_appowner 87
_appserveradm 81
_appserverusr 79
_ard 67
_atsserver 97
_calendar 93
_clamav 82
...

the integer values are actually are positioned strictly vertical, the space between the groupname and the ID is filled with spaces. (the forum software removes these spaces)

I guess the solution would be to pipe the output of the command into a file and then loop through every line

$ sudo dscl . list groups gid >> output.txt

and then something like that:

1 #!/usr/bin/perl 2 3 open(FH, "<output.txt"); 4 while(<FH>) 5 { 6 chomp($_); 7 #parse $_ somehow ... 8 print("current line: $_ \n"); 9 } 10 close(FH);


The question now is. What do I have to do on line 7 in order to find the line with a specific ID, say 87? That would be the following line
...
_appowner 87
...

- how can I find that line?
- how can I extract the group name (_appowner)?

any ideas?

thanks in advance
Ben

In reply to finding a value in a list by baurel

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.