tail

What's the opposite of head? I want all but the first N lines of a file

 ̄綄美尐妖づ 提交于 2019-11-28 04:01:44
Given a text file of unknown length, how can I read, for example all but the first 2 lines of the file? I know tail will give me the last N lines, but I don't know what N is ahead of time. So for a file AAAA BBBB CCCC DDDD EEEE I want CCCC DDDD EEEE And for a file AAAA BBBB CCCC I'd get just CCCC Joe Enos tail --help gives the following: -n, --lines=K output the last K lines, instead of the last 10; or use -n +K to output lines starting with the Kth So to filter out the first 2 lines, -n +3 should give you the output you are looking for (start from 3rd). Mike DeMaria Assuming your version of

Value of the last element of a list

你说的曾经没有我的故事 提交于 2019-11-28 02:39:22
问题 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. 回答1: 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

How To watch a file write in PHP?

北慕城南 提交于 2019-11-27 20:39:55
I want to make movement such as the tail command with PHP, but how may watch append to the file? I don't believe that there's some magical way to do it. You just have to continuously poll the file size and output any new data. This is actually quite easy, and the only real thing to watch out for is that file sizes and other stat data is cached in php. The solution to this is to call clearstatcache() before outputting any data. Here's a quick sample, that doesn't include any error handling: function follow($file) { $size = 0; while (true) { clearstatcache(); $currentSize = filesize($file); if (

Printing the last column of a line in a file

荒凉一梦 提交于 2019-11-27 19:47:28
问题 I have a file that is constantly being written to/updated. I want to find the last line containing a particular word, then print the last column of that line. The file looks something like this. More A1/B1/C1 lines will be appended to it over time. A1 123 456 B1 234 567 C1 345 678 A1 098 766 B1 987 6545 C1 876 5434 I tried to use tail -f file | grep A1 | awk '{print $NF}' to print the value 766, but nothing is output. Is there a way to do this? 回答1: You don't see anything, because of

How would you implement tail efficiently?

混江龙づ霸主 提交于 2019-11-27 14:07:44
问题 What is the efficient way to implement tail in *NIX? I came up (wrote) with two simple solution, both using kind of circular buffer to load lines into circular structure (array | doubly linked circular list - for fun). I've seen part of older implementation in busybox and from what I understood, they used fseek to find EOF and then read stuff "backwards". Is there anything cleaner and faster out there? I got asked this on interview and asker did not look satisfied. Thank you in advance. 回答1:

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

核能气质少年 提交于 2019-11-27 14:01:01
问题 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 ? 回答1: #!/bin/bash tail -f logfile | grep 'certain_word' | read -t 1200 dummy_var [ $? -eq 0

Output file lines from last to first in Bash

萝らか妹 提交于 2019-11-27 10:00:02
问题 I want to display the last 10 lines of my log file, starting with the last line - like a normal log reader. I thought this would be a variation of the tail command, but I can't find this anywhere. 回答1: GNU (Linux) uses the following: tail -n 10 <logfile> | tac tail -n 10 <logfile> prints out the last 10 lines of the log file and tac (cat spelled backwards) reverses the order. BSD (OS X) of tail uses the -r option: tail -r -n 10 <logfile> For both cases , you can try the following: if hash tac

How can I get the source code for the linux utility tail?

南楼画角 提交于 2019-11-27 07:26:09
this command is really very useful but where I can get the source code to see what is going on inside . thanks . Stef The tail utility is part of the coreutils on linux. Source tarball: ftp://ftp.gnu.org/gnu/coreutils/coreutils-7.4.tar.gz Source file: http://git.savannah.gnu.org/cgit/coreutils.git/tree/src/tail.c I've always found FreeBSD to have far clearer source code than the gnu utilities. So here's tail.c in the FreeBSD project: http://svnweb.freebsd.org/csrg/usr.bin/tail/tail.c?view=markup Poke around the uclinux site. Since they distributed the software, they are required to make the

Ending tail -f started in a shell script

最后都变了- 提交于 2019-11-27 05:17:00
问题 I have the following. A Java process writing logs to the stdout A shell script starting the Java process Another shell script which executes the previous one and redirects the log I check the log file with the tail -f command for the success message. Even if I have exit 0 in the code I cannot end the tail -f process. Which doesn't let my script to finish. Is there any other way of doing this in Bash? The code looks like the following. function startServer() { touch logfile startJavaprocess >

What's the opposite of head? I want all but the first N lines of a file

独自空忆成欢 提交于 2019-11-27 05:15:55
问题 Given a text file of unknown length, how can I read, for example all but the first 2 lines of the file? I know tail will give me the last N lines, but I don't know what N is ahead of time. So for a file AAAA BBBB CCCC DDDD EEEE I want CCCC DDDD EEEE And for a file AAAA BBBB CCCC I'd get just CCCC 回答1: tail --help gives the following: -n, --lines=K output the last K lines, instead of the last 10; or use -n +K to output lines starting with the Kth So to filter out the first 2 lines, -n +3