(imported comment written by SystemAdmin)
You have the right plan, which is to think about what you’re trying to do and separate out each specific task. The way I did it was different from andersje and also happens to take care of the concern about doing multiple reads of the files.
For the passwd file, you are pretty much just taking a large beginning chunk of each line, the first element we’ll use to match and the second we will need to discard. So, lets create a relevance that will pull out the data we need:
Q: ( (preceding text of first “:” of it &":"& following text of first “:” of following text of first “:” of it)of preceding text of last “:” of it ) of lines of file “c:\temp\passwd.txt”
A: root:0:0:Admin Team:/root
A: bin:1:1:Admin Team:/bin
Then follow the same process for the shadow file, but because we just need the first part of the line and then one other item (buried in the middle of the string), rather than use multiple “preceding text/following text” statements to try to strip it out, we’ll use a regex to filter out just the parts we need.
Q: ( (parenthesized part 1 of it &":"& parenthesized part 2 of it) of match (regex "
(.):.:.:.:(.):.:.:.:.;") of it) of lines whose (it contains regex "
a-zA-Z0-9
:
$a-zA-Z0-9
a-zA-Z0-9
" ) of file “c:\temp\shadow.txt”
A: root:90
A: bin:90
Once we know how to derive the sub-elements of the lines of the files, we want to pull the matching lines out of each file in turn.
Q: (item 0 of it, item 1 of it) whose (preceding text of first “:” of item 0 of it = preceding text of first “:” of item 1 of it) of (lines of file “c:\temp\passwd.txt”, lines whose (it contains regex "^
a-zA-Z0-9
*:
$a-zA-Z0-9
a-zA-Z0-9
" ) of file “c:\temp\shadow.txt”)
We then add the relevance statements we created earlier to the “item 0 of it, item 1 of it” code, which gets us very close to the final result.
For the last changes, we only need to append “:” and the second half of our “item 1 of it” (which is the number of days from the shadow file) and then finally adjust the format by splitting the string on “:” and combining it again using “,”.
Q: (concatenation “,” of substrings separated by “:” of (item 0 of it &":"& following text of first “:” of item 1 of it)) of (((preceding text of first “:” of it &":"& following text of first “:” of following text of first “:” of it)of preceding text of last “:” of item 0 of it), ( (parenthesized part 1 of it &":"& parenthesized part 2 of it) of match (regex "
(.):.:.:.:(.):.:.:.:.;") of item 1 of it) ) whose (preceding text of first “:” of item 0 of it = preceding text of first “:” of item 1 of it) of (lines of file “c:\temp\passwd.txt”, lines whose (it contains regex "
a-zA-Z0-9
:
$a-zA-Z0-9
a-zA-Z0-9
" ) of file “c:\temp\shadow.txt”)
A: root,0,0,Admin Team,/root,90
A: bin,1,1,Admin Team,/bin,90
T: 2.807 ms
I: plural string
Hope this helps.
-Jim