Movatterモバイル変換


[0]ホーム

URL:


CFEngine documentation homepage

readstringarray

Suggest changes
Table of contents

Prototype:readstringarray(array, filename, comment, split, maxentries, maxbytes)

Return type:int

Description: Populatesarray with up tomaxentries values, parsed fromthe firstmaxbytes bytes in filefilename.

Reads a two dimensional array from a file. One dimension is separated by theregexsplit, the other by the lines in the file. The first field of thelines names the first array argument.

Thecomment field is a multiline regular expression and will strip outunwanted patterns from the file being read, leaving unstripped characters to besplit into fields. Using the empty string ("") indicates no comments.

Returns the number of keys in the array, i.e., the number oflines matched.

Arguments:

  • array : Array identifier to populate, in the range[a-zA-Z0-9_$(){}\[\].:]+
  • filename : File name to read, in the range"?(/.*)
  • comment :Unanchored regex matching comments, in the range.*
  • split :Unanchored regex to split lines into fields, in the range.*
  • maxentries : Maximum number of entries to read, in the range0,99999999999
  • maxbytes : Maximum bytes to read, in the range0,99999999999

Example:

code
readintarray("array_name","/tmp/array","#[^\n]*",":",10,4000);

Input:

code
1:5:7:21:132:19:8:14:143:45:1:78:224:64:2:98:99

Results in:

code
array_name[1][0]1array_name[1][1]5array_name[1][2]7array_name[1][3]21array_name[1][4]13array_name[2][0]2array_name[2][1]19array_name[2][2]8array_name[2][3]14array_name[2][4]14array_name[3][0]3array_name[3][1]45array_name[3][2]1array_name[3][3]78array_name[3][4]22array_name[4][0]4array_name[4][1]64array_name[4][2]2array_name[4][3]98array_name[4][4]99
code
readstringarray("array_name","/tmp/array","\s*#[^\n]*",":",10,4000);

Input:

code
at:x:25:25:Batchjobsdaemon:/var/spool/atjobs:/bin/bashavahi:x:103:105:UserforAvahi:/var/run/avahi-daemon:/bin/false# Disallow loginbeagleindex:x:104:106:UserforBeagleindexing:/var/cache/beagle:/bin/bashbin:x:1:1:bin:/bin:/bin/bash# Daemon has the default shelldaemon:x:2:2:Daemon:/sbin:

Results in a systematically indexed map of the file:

code
...array_name[daemon][0]daemonarray_name[daemon][1]xarray_name[daemon][2]2array_name[daemon][3]2array_name[daemon][4]Daemonarray_name[daemon][5]/sbinarray_name[daemon][6]/bin/bash...array_name[at][3]25array_name[at][4]Batchjobsdaemonarray_name[at][5]/var/spool/atjobsarray_name[at][6]/bin/bash...array_name[games][3]100array_name[games][4]Gamesaccountarray_name[games][5]/var/gamesarray_name[games][6]/bin/bash...

Prepare:

code
echo "1: 5.0:7:21:13" > /tmp/readrealarray.txtecho "2:19:8.1:14:14" >> /tmp/readrealarray.txtecho "3:45:1:78.2:22" >> /tmp/readrealarray.txtecho "4:64:2:98:99.3" >> /tmp/readrealarray.txt

Run:

code
bundleagentmain{vars:"lines"int=>readrealarray("array_name","/tmp/readrealarray.txt","#[^\n]*",":",10,4000);reports:"array_name contains$(lines) keys$(const.n)$(with)"with=>string_mustache("","array_name");}

Output:

code
R: array_name contains 4 keys{      "1": {             "0": "1",             "1": " 5.0",             "2": "7",             "3": "21",             "4": "13"      },      "2": {             "0": "2",             "1": "19",             "2": "8.1",             "3": "14",             "4": "14"      },      "3": {             "0": "3",             "1": "45",             "2": "1",             "3": "78.2",             "4": "22"      },      "4": {             "0": "4",             "1": "64",             "2": "2",             "3": "98",             "4": "99.3"      }}

See also:readrealarray(),readintarray(),parserealarray(),parserealarray(),parsestringarray()

Still need help?

Chat Ask a question on Github Mailing list
Version 
master3.24 (LTS)3.21 (LTS)view all versions

[8]ページ先頭

©2009-2025 Movatter.jp