tail

Get last n lines or bytes of a huge file in Windows (like Unix's tail). Avoid time consuming options

只谈情不闲聊 提交于 2019-11-30 06:37:17
I need to retrieve the last n lines of huge files (1-4 Gb), in Windows 7. Due to corporate restrictions, I cannot run any command that is not built-in. The problem is that all solutions I found appear to read the whole file, so they are extremely slow. Can this be accomplished, fast? Notes: I managed to get the first n lines, fast. It is ok if I get the last n bytes. (I used this https://stackoverflow.com/a/18936628/2707864 for the first n bytes). Solutions here Unix tail equivalent command in Windows Powershell did not work. Using -wait does not make it fast. I do not have -tail (and I do not

Shell function to tail a log file for a specific string for a specific time

£可爱£侵袭症+ 提交于 2019-11-30 04:55:57
I need to the following things to make sure my application server is Tail a log file for a specific string Remain blocked until that string is printed However if the string is not printed for about 20 mins quit and throw and exception message like "Server took more that 20 mins to be up" If string is printed in the log file quit the loop and proceed. Is there a way to include time outs in a while loop ? #!/bin/bash tail -f logfile | grep 'certain_word' | read -t 1200 dummy_var [ $? -eq 0 ] && echo 'ok' || echo 'server not up' This reads anything written to logfile, searches for certain_word,

How do I get the last non-empty line of a file using tail in Bash?

混江龙づ霸主 提交于 2019-11-30 03:14:08
How do I get the last non-empty line using tail under Bash shell? For example, my_file.txt looks like this: hello hola bonjour (empty line) (empty line) Obviously, if I do tail -n 1 my_file.txt I will get an empty line. In my case I want to get bonjour . How do I do that? You can use Awk: awk '/./{line=$0} END{print line}' my_file.txt This solution has the advantage of using just one tool. Use tac, so you dont have to read the whole file: tac FILE |egrep -m 1 . RichieHindle How about using grep to filter out the blank lines first? $ cat rjh 1 2 3 $ grep "." rjh | tail -1 3 Instead of tac you

Python to emulate remote tail -f?

早过忘川 提交于 2019-11-30 03:13:28
问题 We have several application servers, and a central monitoring server. We are currently running ssh with "tail -f" from the monitoring server to stream several text logfiles in realtime from the app servers. The issue, apart from the brittleness of the whole approach is that killing the ssh process can sometimes leave zombie tail processes behind. We've mucked around with using -t to create pseudo-terminals, but it still sometimes leaves the zombie processes around, and -t is apparently also

Web implementation of “tail -f filename”?

 ̄綄美尐妖づ 提交于 2019-11-29 14:27:21
问题 I have a log file and want to create a webpage (possibly Python but not strictly) that will work much like unix "tail -f filename" command works (show new log lines when they are written to file). So that user will continuously see log right in browser. How would you implement this? 回答1: Tailon is a python webapp that, among other things, provides tail -f like functionality. In addition, wtee (a sister project of tailon) can make all its stdin viewable in the browser - its use is identical to

Tailing Log File and Write results to new file

血红的双手。 提交于 2019-11-29 13:24:33
I'm not sure how to word this so I'll type it out and then edit and answer any questions that come up.. Currently on my local network device (PHP4 based) I'm using this to tail a live system log file: http://commavee.com/2007/04/13/ajax-logfile-tailer-viewer/ This works well and every 1 second it loads an external page (logfile.php) that does a tail -n 100 logfile.log The script doesn't do any buffering so the results it displayes onscreen are the last 100 lines from the log file. The logfile.php contains : <? // logtail.php $cmd = "tail -10 /path/to/your/logs/some.log"; exec("$cmd 2>&1",

Value of the last element of a list

一个人想着一个人 提交于 2019-11-29 09:13:05
how to get the value of the last element of a List? I've noted that List.hd (or .Head) return an item, while List.tl (or .Tail) returns a List. Is rev the List and get the hd the only way around? Thanks. Try this function. It uses recursion, though it gets optimised to iteration anyway since it's tail recursion. In any case, it is most likely quicker than reversing the entire list (using List.rev ). let rec last = function | hd :: [] -> hd | hd :: tl -> last tl | _ -> failwith "Empty list." The answer of Pavel Minaev is definitely worth taking into account, however. Nonetheless, the algorithm

How to tail -f the latest log file with a given pattern

为君一笑 提交于 2019-11-29 08:18:20
问题 I work with some log system which creates a log file every hour, like follows: SoftwareLog.2010-08-01-08 SoftwareLog.2010-08-01-09 SoftwareLog.2010-08-01-10 I'm trying to tail to follow the latest log file giving a pattern (e.g. SoftwareLog*) and I realize there's: tail -F (tail --follow=name --retry) but that only follow one specific name - and these have different names by date and hour. I tried something like: tail --follow=name --retry SoftwareLog*(.om[1]) but the wildcard statement is

How do you continuously read a file in Java?

江枫思渺然 提交于 2019-11-29 05:45:39
I'm trying to figure out how to continuously read a file and once there is a new line added, output the line. I'm doing this using a sleep thread however it just seems to blow through the whole file and exit the program. Any suggestions what I'm doing wrong? Here is my code: import java.io.*; import java.lang.*; import java.util.*; class jtail { public static void main (String args[]) throws InterruptedException, IOException{ BufferedReader br = new BufferedReader( new FileReader("\\\\server01\\data\\CommissionPlanLog.txt")); String line = null; while (br.nextLine ) { line = br.readLine(); if

tail -f into grep into cut not working properly

爷,独闯天下 提交于 2019-11-29 05:38:30
i'm trying to build a shell script to monitor some log files. I'm using a command like this: tail -f /var/somelog | grep --line-buffered " some test and p l a c e h o l d e r" | cut -f 3,4,14 -d " " the log file is like: some test and p l a c e h o l d e r 3 some test and p l a c e h o l d e r 4 some test and p l a c e h o l d e r 5 some test and p l a c e h o l d e r 6 and so on.. My issue is that the output of the command does not display the last line some test and p l a c e h o l d e r 6 until line some test and p l a c e h o l d e r 7 is added to the log. I hope I made clear my issue. Can