0

たとえば、処理する必要があるテキスト ファイルのコレクションがあるとします (たとえば、特定のラベルを検索して値を抽出するなど)。問題に取り組むための一般的な方法は何ですか?

私もこれを読みました:「Pythonから変数値を取得する」しかし、私が直面しているいくつかのケースには当てはまらないようです( のtab代わりに like が使用されています:

使用する言語に関係なく、問題に取り組むための最も適切な方法を知りたいだけです。

次のようなものがあるとします。

Name: Backup Operators  SID: S-1-5-32-551   Caption: COMMSVR21\Backup Operators Description: Backup Operators can override security restrictions for the sole purpose of backing up or restoring files  Domain: COMMSVR21   
COMMERCE/cabackup
COMMSVR21/sys5erv1c3

Backup Operatorsの値にアクセス/取得し、その代わりにCOMMERCE/cabackup&を取得できるようにしたいと考えていますCOMMSVR21/sys5erv1c3

どのようにしますか?

私が考えたのは、テキスト ファイル全体、正規表現検索、およびおそらくいくつかの if else ステートメントを読み取ることです。これは効果的ですか?それとも、テキスト ファイルをおそらく何らかの配列に解析して取得するのでしょうか。わからない。

別の例のように、次のように言います。

        GPO: xxx & yyy Servers
            Policy:            MaximumPasswordAge
            Computer Setting:  45

テキスト ファイルをチェックしPolicy = MaximumPasswordAgeて値を返すにはどうすればよいでしょう45か。

ありがとう!

p/s -- 私はこれを Python (知識がないため、その場で取り上げる) または Java で行っている可能性があります。

pp/s -- スポイラー タグがないことに気付きました。うーん

--

ログの例: ディレクトリ権限のあるログ:

C:\:
    BUILTIN\Administrators  Allowed:    Full Control
    NT AUTHORITY\SYSTEM Allowed:    Full Control
    BUILTIN\Users   Allowed:    Read & Execute
    BUILTIN\Users   Allowed:    Special Permissions: 
            Create Folders
    BUILTIN\Users   Allowed:    Special Permissions: 
            Create Files
    \Everyone   Allowed:    Read & Execute
    (No auditing)

C:\WINDOWS:
    BUILTIN\Users   Allowed:    Read & Execute
    BUILTIN\Power Users Allowed:    Modify
    BUILTIN\Power Users Allowed:    Special Permissions: 
            Delete
    BUILTIN\Administrators  Allowed:    Full Control
    NT AUTHORITY\SYSTEM Allowed:    Full Control
    (No auditing)

次の別のもの:

    Audit Policy
    ------------
        GPO: xxx & yyy Servers
            Policy:            AuditPolicyChange
            Computer Setting:  Success

        GPO: xxx & yyy Servers
            Policy:            AuditPrivilegeUse
            Computer Setting:  Failure

        GPO: xxx & yyy Servers
            Policy:            AuditDSAccess
            Computer Setting:  No Auditing

これはタブ区切りのものです:

User Name   Full Name   Description Account Type    SID Domain  PasswordIsChangeable    PasswordExpires PasswordRequired    AccountDisabled AccountLocked   Last Login
53cuR1ty        Built-in account for administering the computer/domain  512 S-1-5-21-2431866339-2595301809-2847141052-500   COMMSVR21   True    False   True    False   False   09/11/2010 7:14:27 PM
ASPNET  ASP.NET Machine Account Account used for running the ASP.NET worker process (aspnet_wp.exe) 512 
4

1 に答える 1

1

I always shove Python into people's faces ;)

I recommend looking at Regex: http://docs.python.org/howto/regex.html, as it might fit your needs. I won't do it for you (because I can't), but I know this will work if your files are colon-delimited key/value pairs separated by newline characters. Here's a quick start (which might work):

regex = '(.*):( *)(.*)\n'

This matches three groups (hopefully): A group before the colon (group 1), the spaces (group 2, which can be thrown away), and the text between that and a new line (group 3).

Play with that (I don't want to have a regex aneurysm, so this is far as I can help for now). Good luck!

于 2011-01-06T03:53:32.507 に答える