Tenzir supports reading from and writing to files, including non-regular files, such as Unix domain sockets, standard input, standard output, and standard error.
When ~ is the first character in the file path, the operator substitutes it
with the $HOME environment variable.
Use from_file to read files with glob
patterns, automatic format detection, and file monitoring. For writing, use
save_file with a print operator.
Examples
Section titled “Examples”Read a file
Section titled “Read a file”Read from a file and parse it in the format implied by the file extension:
from_file "/tmp/file.json"The operator automatically decompresses the file when the suffix list contains a supported compression algorithm:
from_file "/tmp/file.json.gz"Read multiple files with a glob pattern
Section titled “Read multiple files with a glob pattern”from_file "/var/log/*.json"Watch a directory for new files
Section titled “Watch a directory for new files”Use watch=true to continuously monitor for new files:
from_file "/var/log/app/*.json", watch=trueWrite a file
Section titled “Write a file”Write to a file in a specific format:
versionprint_jsonsave_file "/tmp/tenzir-version.json"With compression:
versionprint_jsoncompress_bz2save_file "/tmp/tenzir-version.json.bz2"Append to a file
Section titled “Append to a file”In case the file exists and you do not want to overwrite it, pass append=true
as option:
from {x: 42}print_csvsave_file "/tmp/event.csv", append=trueRead/write a Unix domain socket
Section titled “Read/write a Unix domain socket”Pass uds=true to signal that the file is a Unix domain socket:
print_ndjsonsave_file "/tmp/socket", uds=trueWhen reading from a Unix domain socket, use
from_file with a parsing pipeline:
from_file "/tmp/socket" { read_ndjson}