• Places
    • Home
    • Graphs
    • Prefixes
  • Admin
    • Users
    • Settings
    • Plugins
    • Statistics
  • CPACK
    • Home
    • List packs
    • Submit pack
  • Repository
    • Load local file
    • Load from HTTP
    • Load from library
    • Remove triples
    • Clear repository
  • Query
    • YASGUI SPARQL Editor
    • Simple Form
    • SWISH Prolog shell
  • Help
    • Documentation
    • Tutorial
    • Roadmap
    • HTTP Services
  • Login

Managing external tables for SWI-Prolog
All Application Manual Name SummaryHelp

  • Documentation
    • Reference manual
    • Packages
      • Managing external tables for SWI-Prolog
        • Introduction
        • Managing external tables
        • Flexible ordering and equivalence based on character table
        • Example: accessing the Unix passwd file

4 Example: accessing the Unix passwd file

The Unix passwd file is a file with records spanning a single line each. The fields are separated by a single‘:’character. Here is an example of a line:

joe:hgdu3r3bce:53:100:Joe Johnson:/users/joe:/bin/bash

The following call defines a table for it:

?- new_table('/etc/passwd',
             [ user(atom),
               passwd(code_list),
               uid(integer),
               gid(integer),
               gecos(code_list),
               homedir(atom),
               shell(atom)
             ],
             [ field_separator(0':)
             ],
             H).

To find all people of group 100, use:

?- findall(User, in_table(H, [user(User), gid(100)], _), Users).

ClioPatria (version V3.1.1-51-ga0b30a5)