print / cat only new lines in log files
Project description
newcat
print (cat) only new lines in files (after previous run of newcat). This is useful to parse recent log records.
Install
pipx install newcat
Example
$ echo This is line 1 > /tmp/test.log
# works like normal /bin/cat now
$ newcat /tmp/test.log
This is line 1
# only new lines are printed
$ echo This is line 2 >> /tmp/test.log
$ newcat /tmp/test.log
This is line 2
# no new lines => nothing on stderr
$ newcat /tmp/test.log
# despite file is having two lines
$ cat /tmp/test.log
This is line 1
This is line 2
How does this magic work?
newcat stores some info about file (including position in file) in state file. Default state file is /tmp/.newcat.state
, but can be overriden with NEWCAT_STATE
environment variable or -s
/ --state
option. Normally, newcat prints file content starting from this position (which was saved before), thus lines which were already printed before, will not be printed on new newcat run.
Sometime file content it rewritten (e.g. after echo New content > /tmp/test.log
). To detect this situation newcat checks two things:
- file inode changed
- file size is less then old printed position
if any of these conditions are met, file considered as rewritten and newcat prints it from the beginning. Note: this is not absolutely reliable, and there is a chance that sometimes newcat will not detect when file is overwritten.
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
File details
Details for the file newcat-0.0.1.tar.gz
.
File metadata
- Download URL: newcat-0.0.1.tar.gz
- Upload date:
- Size: 2.9 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/4.0.1 CPython/3.9.2
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | c8defe690bc858759d0e222e398d20b8a9ab2530ebf96b7db45e6a6ba5c7106c |
|
MD5 | f05a977930b4c45ac05330bdcc05b1e1 |
|
BLAKE2b-256 | aa391ae84436be14d9f7c32ed67f1ff1b65f25bf1f61b2db852fa9580513cd25 |
File details
Details for the file newcat-0.0.1-py3-none-any.whl
.
File metadata
- Download URL: newcat-0.0.1-py3-none-any.whl
- Upload date:
- Size: 3.6 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/4.0.1 CPython/3.9.2
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 8a9623dd610085ddbdcabef99132278bcc2e887f402a8a46f398293288bdca15 |
|
MD5 | db9e85da196ae62fdaccf6d7f76c0373 |
|
BLAKE2b-256 | 07bf6068a2e5c88ce97ad797ede01b6f625dbcfb2dcc42088993b201965c778f |