tail

How to move first N bytes from text file to another text file

五迷三道 提交于 2019-12-11 14:55:26
问题 I've got an extreme problem, and all of the solutions I can imagine are complicated. According to my UNIX/Linux experience there must be an easy way. I want to delete the first n bytes of file in log.txt.file is long enough. Well, I'm sure somebody will deliver me a suprisingly easy solution I just can't imagine. 回答1: I am not sure what you want: Your headline says move first N byte to another file, your text says you want to delete the first N bytes tail -c +N log.txt Will output everything

tail -f | awk and end tail once data is found

强颜欢笑 提交于 2019-12-11 08:36:44
问题 I am trying to build a script which tail -f | awk the log file which is getting updated every second. awk part will fetch me only the required part of the log file based on my search parameter. Output XML is also captured in an output file. Script is working fine - as expected. Issue - However ever after the search is performed it stays hung due to tail -f . Any idea how to update below script - so that once the output XML is captured, it should break the tail part?? XMLF=/appl/logs/abc.log

Ansible - How to loop through command with items until registered variables are equal?

一笑奈何 提交于 2019-12-11 08:01:26
问题 I'm trying to find if a file has had any writes in the last 15 seconds. - name: 'Check File for Writes' shell: tail -n 50 /path/to/some/file | sha1sum loop: - 1 - 2 register: file_writes loop_control: pause: 15 until: file_writes.results[0].stdout == file_writes.results[1].stdout The expected behavior is as follows: 1.) This task would run the 'tail' command once 2.) It would then wait for 15 seconds 3.) Then run the 'tail' command again 4.) The outputs of both tail commands would be

Exit tail upon string detection

为君一笑 提交于 2019-12-11 03:06:41
问题 I'm writing a barrier to stop to hold the execution of a script until a certain keyword is logged. The script is pretty simple: tail -F -n0 logfile.log | while read LINE; do [[ "$LINE" == *'STOP'* ]] && echo ${LINE} && break; done or tail -F -n0 logfile.log | grep -m1 STOP Still, despite printing STOP as soon as it is detected, these chunks of code terminate only after the following line is written . I.e: printf "foo\n" >> logfile.log # keeps reading printf "foo\n" >> logfile.log # keeps

how to calculate sum|mean|median for tail of each group when pandas data aggregated in python

强颜欢笑 提交于 2019-12-11 02:25:40
问题 i am having data like following.which is in pandas data frame format. A B C D E F G 1 1 2 3 1 4 2 1 1 2 4 5 6 7 1 1 2 3 2 3 2 1 1 2 4 5 6 7 2 1 2 3 2 3 4 2 1 2 3 4 3 3 2 1 2 4 5 6 7 here agg_lvl=['A','B','C'] I want to calculate mean|median|sum for G variable by using tail(2) records in each group when data aggregated to agg_lvl. And my expected output is like this: expected output for mean: A B C G 1 1 2 4.5 2 1 2 5 the output will be same for median and sum also,but in place of mean we have

grep 3 latest occurences and some lines around the occurence

喜你入骨 提交于 2019-12-11 01:14:10
问题 I have a file like: exception: anythinggggg... exception: anythinggggg... abchdhjsdhsd ygsuhesnkc exception: anythingggg... exception: anything... .. .. I want to grep the latest 2 occurrences of exception keyword along with 3 lines before and 3 lines after it. I am using something like grep -C 3 exception | tail -12 I am using tail -12 here as I want 6 lines per occurrence and latest 2 occurrences. this works fine when occurrences of exception are far off from each other but gives me useless

Paramiko Expect - Tailing

百般思念 提交于 2019-12-10 21:06:13
问题 I am trying to tail a log file, and it works. But I need to also be able to analyze the output and log for errors and such. I am using the base example on the Paramiko-expect github page and I can not figure out how to do this. import traceback import paramiko from paramikoe import SSHClientInteraction def main(): # Set login credentials and the server prompt hostname = 'server' username = 'username' password = 'xxxxxxxx' port = 22 # Use SSH client to login try: # Create a new SSH client

Understanding the “tail -f in python”

泪湿孤枕 提交于 2019-12-10 20:15:35
问题 I have created a very simple python script: def read_then_follow(file): for line in file: yield line while True: line = file.readline() if not line: time.sleep(1.0) continue yield line for line in read_then_follow("some_file.txt"): print line The file "some_file.txt" contains a few lines of text, which will be written to screen when I run the script. If I then add a line to the file with echo "line" >> some_file.txt , the line will be printed to the screen within 1 second. But: if I open the

How to modify a prefix of a Kotlin sequence but retain the tail?

。_饼干妹妹 提交于 2019-12-10 19:32:39
问题 Kotlin provides take and takeWhile methods which let one to take first n items of a Sequence<T> and process them separately as another sequence, for example, drop some of them, map to other values etc. But when I use take and takeWhile , the tail of the sequence is dropped. Now, given a once-constrained sequence, how do I transform its arbitrary prefix to another sequence retaining the tail if it remains? Example: val seq = (1..10).asSequence().constrainOnce() // emits 1, 2, 3, 4, 5, 6, 7, 8,

Redirecting tail output into a program

隐身守侯 提交于 2019-12-10 17:13:14
问题 I want to send a program the most recent lines from a text file using tail as stdin. First, I echo to the program some input that will be the same every time, then send in tail input from an inputfile which should first be processed through sed. The following is the command line that I expect to work. But when the program runs it only receives the echo input, not the tail input. (echo "new" && tail -f ~/inputfile 2> /dev/null | sed -n -r 'some regex' && cat) | ./program However, the following