tail

How to read first n-th files from directory (pleaso NOT a “head -n solution”)?

本小妞迷上赌 提交于 2019-12-24 12:30:43
问题 I have a directory with more then 60000 files. How to get only N of them without using a find | head -n or ls | head -n solutions, since find and ls to read this list of files takes too much time. Are there any configs for ls and find or are there any other programs, which can help to safe the time? 回答1: For what it worth: # Create 60000 files sh$ for i in {0..100}; do for j in {0..600}; do touch $(printf "%05d" $(($i+$j*100))); done; done On Linux Debian Wheezy x86_64 w/ext4 file system: sh$

Bash: How to tail then copy multiple files (eg using xargs)?

我的梦境 提交于 2019-12-24 09:30:45
问题 I've been trying various combinations of xargs and piping but I just can't get the right result. Previous questions don't quite cover exactly what I want to do: I have a source directory somewhere, lets say /foo/source, with a mix of different files I want to copy just the csv files found in source to a different destination, say /foo/dest But I ALSO at the same time need to remove 232 header rows (eg using tail) I've figured out that I need to pipe the results of find into xargs, which can

Tail-Recursive Power Function in Scheme

时间秒杀一切 提交于 2019-12-24 00:57:55
问题 I am having trouble writing a tail-recursive power function in scheme. I want to write the function using a helper function. I know that I need to have a parameter to hold an accumulated value, but I am stuck after that. My code is as follows. (define (pow-tr a b) (define (pow-tr-h result) (if (= b 0) result pow-tr a (- b 1))(* result a)) pow-tr-h 1) I edited my code, and now it works. It is as follows: (define (pow-tr2 a b) (define (pow-tr2-h a b result) (if (= 0 b) result (pow-tr2-h a (- b

C Basic Head Command

☆樱花仙子☆ 提交于 2019-12-23 10:48:07
问题 I'm trying to recreate the head, and tail commands from linux for my programming class. We just started using C so I'm new to the idea of allocating memory and pointers. I'm wondering why this doesn't work. #include <stdio.h> #include <stdlib.h> int main(int argc,char **argv){ /* Checks if correct amount of arguements */ if(argc != 2 || argc != 4){ printf("Usage: %s head <file> \n Or: head <file> -n <number of characters>", argv[0]); exit(-1); } if(strcmp(argv[1], "-n" != 0)){ char fileName

Succinct way to print all lines up until the last line that matches a given pattern

只谈情不闲聊 提交于 2019-12-23 08:50:08
问题 I'm trying to find a succinct shell one-liner that'll give me all the lines in a file up until some pattern. The use case is dumping all the lines in a log file until I spot some marker indicating that the server has been restarted. Here's a stupid shell-only way that: tail_file_to_pattern() { pattern=$1 file=$2 tail -n$((1 + $(wc -l $file | cut -d' ' -f1) - $(grep -E -n "$pattern" $file | tail -n 1 | cut -d ':' -f1))) $file } A slightly more reliable Perl way that takes the file on stdin:

Java read a logfile live

孤者浪人 提交于 2019-12-22 17:32:05
问题 I'm writing a cod4 server controller in Java(I know there are perfectly fine server controllers out there, but I want to learn from it). Now I want to take specific actions according to entries in a logfile, this file is updated by cod very often, and the file can get quite large. Now how do I efficiently read only the part that has changed of the file, every second or so? Or is there a way to send everything that is changed in the logfile live to Java?(I read something about pipes). The

Java read a logfile live

☆樱花仙子☆ 提交于 2019-12-22 17:31:28
问题 I'm writing a cod4 server controller in Java(I know there are perfectly fine server controllers out there, but I want to learn from it). Now I want to take specific actions according to entries in a logfile, this file is updated by cod very often, and the file can get quite large. Now how do I efficiently read only the part that has changed of the file, every second or so? Or is there a way to send everything that is changed in the logfile live to Java?(I read something about pipes). The

Grep after and before lines of last Match

廉价感情. 提交于 2019-12-22 08:37:07
问题 I am searching through few logs and I want to grep the last match along with it's above and below few lines. grep -A10 -B10 "searchString" my.log will print all the matches with after and before 10 lines grep "searchString" my.log | tail -n 1 will print the last match. I want to combine both and get the after and before 10 lines of last match. 回答1: If you like to have all in one command, try this awk awk '/search/ {f=NR} {a[NR]=$0} END {while(i++<NR) if (i>f-3 && i<f+3) print a[i]}' file How

combining head and tail methods in R

流过昼夜 提交于 2019-12-21 18:02:26
问题 I use the head(d) and tail(d) methods in R package utils a lot - frequently one after the other. So i wrote a simple wrapper for the two functions: ht <- function(d, m=5, n=m){ # print the head and tail together cat(" head --> ", head(d,m), "\n", "--------", "\n", "tail --> ", tail(d,n), "\n") } And i got some unexpected results ... can someone please help me understand why? (so i can fix it ... or at least understand your solution!). Some background... Numeric is fine: x <- 1:100 ht(x) As is

following a log file over http

跟風遠走 提交于 2019-12-21 12:18:52
问题 For security reasons (I'm a developer) I do not have command line access to our Production servers where log files are written. I can , however access those log files over HTTP. Is there a utility in the manner of "tail -f" that can "follow" a plain text file using only HTTP? 回答1: You can do this if the HTTP server accepts requests to return parts of a resource. For example, if an HTTP request contains the header: Range: bytes=-500 the response will contain the last 500 bytes of the resource.