Skip to main content
templarian
Gold ⭐️
March 29, 2022
Solved

How to get the last n lines of a text file ("tail -n log.file")

Hi,

 

An external process creates an error.file on certain events and updates the process log file.

 

The process that I'm creating starts when the error.file is created and need to read the last 10 - 15 lines of the log.file. My problem is that the log.file does not rollover and just grows continually and neither follows a log standard in order to use SysLog processors.

 

How can I get that last 10 - 15 lines of the log file? Something like ( "tail -15 log.file" ).

 

Thanks in advance.

araujo
araujoAnswer
Platinum ⭐️⭐️⭐️
March 29, 2022

Hi @templarian ,

 

You can use something like the example below:

araujo_0-1648594388252.png

 

araujo_1-1648594412531.png

Cheers,

André

-- Was your question answered? Please take some time to click on "Accept as Solution" below this post. If you find a reply useful, say thanks by clicking on the thumbs up button.

2 replies

araujo
Platinum ⭐️⭐️⭐️
araujoAnswer
Platinum ⭐️⭐️⭐️
March 29, 2022

Hi @templarian ,

 

You can use something like the example below:

araujo_0-1648594388252.png

 

araujo_1-1648594412531.png

Cheers,

André

Translate
-- Was your question answered? Please take some time to click on "Accept as Solution" below this post. If you find a reply useful, say thanks by clicking on the thumbs up button.
templarian
Gold ⭐️
March 31, 2022

Hi André,

 

That is what I needed. Thanks a lot.

 

For those who are facing the same problem in windows; @araujo's solution also works with Powershell

 

Nifi ExecuteStreamCommand Powershell.png

 

Translate