the above only prints the last 2 lines, and it also searches the entire output for the word "FAILED". i dont want to search the entire output as it can be pretty large. i just want to check the last line of the output, and if this last line contains the word "FAILED", i want the awk to then print the last 200 lines of the output.
so basically, printing the last 200 lines of the output should be dependent only on IF the last line of the output contains the word "FAILED".
i left out the the "file file" in your example because that wont be necessary. what I want to do is output the 200 lines if and only if the last line of the file contains an entry and the entry contain "FAILED". some times the last line of a file or output can be blank. so i also need to account for that.
btw, the "tail -500" in my example is just a good example that explains the type of manner if which the data i'm working on is given to me. so basically, i would have to run the awk command on the output produced by a process.
the output really doesn't matter as it is in no way the same every time. it varies. that's why i gave the tailing of the syslog as an example. you never know what the format of the output will be. and it really doesn't matter as we're only concerned about whether or not the output contain a string.
anyway I can add a "else" into it to print the entire output in the event the last line of the output doesn't contain the "FAILED" string?
so the logic i'm after is,
if the last line of the output contains a string, print x amount of lines in the output received. this requirement has been satisfied with your awk code.
the next logic is, if the last line of the log does not contain the string "FAILED", then print the entire output. no need to print a select number of lines. just print everything
@Akshay, yes something like that should work. I would avoid using rm -rf like that (risky), simply rm . Also you need to know if the temporary file exists and if not use something else, or use a temporary file name that is guaranteed not to exist, and typically use something in the /var/tmp directory..
i'm curious, how did you become so proficient at awk? did you take a specific class? i'm pretty sure they dont go into any significant lenght of training on it at any colleges. so i wanna know how you became so good at it that you can pretty much come up with solutions to any problem (using awk). is awk your favorite programming language? if not, what is? i know this has nothing to do with this thread, i'm just curious.
@Scrutinizer
Yes as you said rm -rf is risky and even its better to use something else instead of tmp . I think from this (post #11 system call) we can overcome from out of memory problem, if file is very lengthy right ?