Sponsored Content
Top Forums UNIX for Beginners Questions & Answers Copy last 30 minutes' contents from a log file Post 303040050 by Chubler_XL on Tuesday 22nd of October 2019 04:15:33 PM
Old 10-22-2019
How I've tackled this type of problem in the past is to have the script "Remember" where it got up to in a file and start from there next time.

Example:
Code:
LOGFILE=/DB2/db2diag.log 
NEWFILE=${LOGFILE%.log}_$(date +%Y%m%d%H%M).log
CHKFILE=/var/scriptdata/db2diagline.dat

EndLine=$(awk 'END{print NR}' $LOGFILE)
if [ -f $CHKFILE ]
then
    read StartLine < $CHFILE
    StartLine=${StartLine:-0}
    # Test for log file truncated
    [ $EndLine -lt $StartLine ] && StartLine=0
else
    StartLine=0
fi

awk -vS=$StartLine -vE=$EndLine 'NR>E{exit} NR>S' $LOGFILE > $NEWFILE

#Save EndLine for StartLine next time
echo "$EndLine" > $CHKFILE


Last edited by Chubler_XL; 10-22-2019 at 05:27 PM.. Reason: Added code to generate new filename (add datetime to original logfile name)
This User Gave Thanks to Chubler_XL For This Post:
 

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Copy selected contents from file

I want to capture contents of a file between 2 strings into another file for eg all lines in between the keywords "start log" and "end log" should be copied into another file (4 Replies)
Discussion started by: misenkiser
4 Replies

2. Shell Programming and Scripting

Automatic Copy of File Contents to Clipboard

Could someone show me how to copy the contents of a file to the clipboard automatically without manually selecting its contents? I just want to press the "Paste Key" to show the results. I wish to use this in a ksh script. I'm using Solaris. Thanks! (5 Replies)
Discussion started by: ilak1008
5 Replies

3. Shell Programming and Scripting

Bash copy file contents into an existing file at a specific location

Hi all I need to copy the entire contents of one file into an existing file at a specific location. I know the exact line number where I need to put it. It appears I would use either sed or awk to do this, but I have been unsuccessful so far: File A line 1 line 2 line 3 line 4 ... (6 Replies)
Discussion started by: gshepherd7
6 Replies

4. Shell Programming and Scripting

Copy contents of a directory only if a file exists

I'm looking to write a script that will check the contents of a directory, and if any files exist in that directory copy them to a temporary folder. The target files are only resident for a few seconds, so I think the script needs to be running constantly. Any pointers would be really... (3 Replies)
Discussion started by: danceofillusion
3 Replies

5. Shell Programming and Scripting

copy the contents between two keywords to a new file.

Hi All, I want to edit my gate level netlists by searching for the content between two patterns eg: ff1 \test/a0 ( .CLK(\test/ClkInt0_acb_00x1 ),.D(\test/Rakicc ), .QB(\test/X ), .VDD(1'b1), .VSS(1'b0)); ff1 \test/a1 ( .CLK(\test/medis0_acb_00x1 ),.D(\test/hedwc ), .QB(\test/X ),... (6 Replies)
Discussion started by: naveen@
6 Replies

6. UNIX for Dummies Questions & Answers

Copy entire contents of file to clipboard

Hi, I am trying to figure out how to copy the contents of a file to the clipboard, then paste into a command. i.e copy contents of file /path/filename.txt to <command> <paste text> Hope that makes sense. Basically tryting to copy the text for use in a command without having to open the... (8 Replies)
Discussion started by: JCA70
8 Replies

7. Shell Programming and Scripting

Need help to copy contents of a file

Hi, I am stuck up with a problem of copying the contents of a directory where one of the folder name is changed daily. Problem: I have the folder structure as: RefWorlds2/LINGCC4_X64/odsdev/odessy/UTI/621GA_build_xxx/.../.. In the above path the build number (xxx) will be changed... (3 Replies)
Discussion started by: SathaKarni
3 Replies

8. Shell Programming and Scripting

Need Script to copy the contents of two files into one file

Hi i need Script to copy the contents of two files into one file i have 2 fil X1.txt / X2.txt i need script to copy the contents of X1 and X2 In AllXfile X1.txt File X1 X2.txt File X2 AllXfile.txt File X1 File X2 (2 Replies)
Discussion started by: azzeddine2005
2 Replies

9. Shell Programming and Scripting

Copy contents of one file to another

I need to write a script (in bash) that copies the content of the first file in each folder of a directory to the second file in the same folder. I tried this and it didn't work - it just came back with errors and I'm not sure how to fix it. Help is very much appreciated! for mpdir in... (4 Replies)
Discussion started by: LeftoverStew
4 Replies

10. Shell Programming and Scripting

Grep a log file for the last 5 minutes of contents every 5 minutes

Hi all, System Ubuntu 16.04.3 LTS i have the following log INFO 2019-02-07 15:13:31,099 module.py:700] default: "POST /join/8550614e-3e94-4fa5-9ab2-135eefa69c1b HTTP/1.0" 500 2042 INFO 2019-02-07 15:13:31,569 module.py:700] default: "POST /join/6cb9c452-dcb1-45f3-bcca-e33f5d450105... (15 Replies)
Discussion started by: charli1
15 Replies
epp_dodger(3erl)					     Erlang Module Definition						  epp_dodger(3erl)

NAME
epp_dodger - epp_dodger - bypasses the Erlang preprocessor. DESCRIPTION
epp_dodger - bypasses the Erlang preprocessor. This module tokenises and parses most Erlang source code without expanding preprocessor directives and macro applications, as long as these are syntactically "well-behaved". Because the normal parse trees of the erl_parse module cannot represent these things (normally, they are expanded by the Erlang preprocessor epp(3erl) before the parser sees them), an extended syntax tree is created, using the erl_syntax mod- ule. DATA TYPES
errorinfo() = {ErrorLine::integer(), Module::atom(), Descriptor::term()} : This is a so-called Erlang I/O ErrorInfo structure; see the io(3erl) module for details. EXPORTS
parse(Dev::IODevice) -> {ok, Forms} | {error, errorinfo()} Equivalent to parse(IODevice, 1) . parse(Dev::IODevice, L::StartLine) -> {ok, Forms} | {error, errorinfo()} Types IODevice = pid() StartLine = integer() Forms = [syntaxTree() (see module erl_syntax)] Equivalent to parse(IODevice, StartLine, []) . See also: parse/1 . parse(Dev::IODevice, L0::StartLine, Options) -> {ok, Forms} | {error, errorinfo()} Types IODevice = pid() StartLine = integer() Options = [term()] Forms = [syntaxTree() (see module erl_syntax)] Reads and parses program text from an I/O stream. Characters are read from IODevice until end-of-file; apart from this, the behav- iour is the same as for parse_file/2 . StartLine is the initial line number, which should be a positive integer. See also: parse/2 , parse_file/2 , parse_form/2 , quick_parse/3 . parse_file(File) -> {ok, Forms} | {error, errorinfo()} Types File = filename() (see module file) Forms = [syntaxTree() (see module erl_syntax)] Equivalent to parse_file(File, []) . parse_file(File, Options) -> {ok, Forms} | {error, errorinfo()} Types File = filename() (see module file) Options = [term()] Forms = [syntaxTree() (see module erl_syntax)] Reads and parses a file. If successful, {ok, Forms} is returned, where Forms is a list of abstract syntax trees representing the "program forms" of the file (cf. erl_syntax:is_form/1 ). Otherwise, {error, errorinfo()} is returned, typically if the file could not be opened. Note that parse errors show up as error markers in the returned list of forms; they do not cause this function to fail or return {error, errorinfo()} . Options: {no_fail, boolean()} : If true , this makes epp_dodger replace any program forms that could not be parsed with nodes of type text (see erl_syn- tax:text/1 ), representing the raw token sequence of the form, instead of reporting a parse error. The default value is false . {clever, boolean()} : If set to true , this makes epp_dodger try to repair the source code as it seems fit, in certain cases where parsing would oth- erwise fail. Currently, it inserts ++ -operators between string literals and macros where it looks like concatenation was intended. The default value is false . See also: parse/2 , quick_parse_file/1 , erl_syntax:is_form/1 . parse_form(Dev::IODevice, L0::StartLine) -> {ok, Form, LineNo} | {eof, LineNo} | {error, errorinfo(), LineNo} Types IODevice = pid() StartLine = integer() Form = syntaxTree() (see module erl_syntax) LineNo = integer() Equivalent to parse_form(IODevice, StartLine, []) . See also: quick_parse_form/2 . parse_form(Dev::IODevice, L0::StartLine, Options) -> {ok, Form, LineNo} | {eof, LineNo} | {error, errorinfo(), LineNo} Types IODevice = pid() StartLine = integer() Options = [term()] Form = syntaxTree() (see module erl_syntax) LineNo = integer() Reads and parses a single program form from an I/O stream. Characters are read from IODevice until an end-of-form marker is found (a period character followed by whitespace), or until end-of-file; apart from this, the behaviour is similar to that of parse/3 , except that the return values also contain the final line number given that StartLine is the initial line number, and that {eof, LineNo} may be returned. See also: parse/3 , parse_form/2 , quick_parse_form/3 . quick_parse(Dev::IODevice) -> {ok, Forms} | {error, errorinfo()} Equivalent to quick_parse(IODevice, 1) . quick_parse(Dev::IODevice, L::StartLine) -> {ok, Forms} | {error, errorinfo()} Types IODevice = pid() StartLine = integer() Forms = [syntaxTree() (see module erl_syntax)] Equivalent to quick_parse(IODevice, StartLine, []) . See also: quick_parse/1 . quick_parse(Dev::IODevice, L0::StartLine, Options) -> {ok, Forms} | {error, errorinfo()} Types IODevice = pid() StartLine = integer() Options = [term()] Forms = [syntaxTree() (see module erl_syntax)] Similar to parse/3 , but does a more quick-and-dirty processing of the code. See quick_parse_file/2 for details. See also: parse/3 , quick_parse/2 , quick_parse_file/2 , quick_parse_form/2 . quick_parse_file(File) -> {ok, Forms} | {error, errorinfo()} Types File = filename() (see module file) Forms = [syntaxTree() (see module erl_syntax)] Equivalent to quick_parse_file(File, []) . quick_parse_file(File, Options) -> {ok, Forms} | {error, errorinfo()} Types File = filename() (see module file) Options = [term()] Forms = [syntaxTree() (see module erl_syntax)] Similar to parse_file/2 , but does a more quick-and-dirty processing of the code. Macro definitions and other preprocessor direc- tives are discarded, and all macro calls are replaced with atoms. This is useful when only the main structure of the code is of interest, and not the details. Furthermore, the quick-parse method can usually handle more strange cases than the normal, more exact parsing. Options: see parse_file/2 . Note however that for quick_parse_file/2 , the option no_fail is true by default. See also: parse_file/2 , quick_parse/2 . quick_parse_form(Dev::IODevice, L0::StartLine) -> {ok, Form, LineNo} | {eof, LineNo} | {error, errorinfo(), LineNo} Types IODevice = pid() StartLine = integer() Form = syntaxTree() (see module erl_syntax) | none LineNo = integer() Equivalent to quick_parse_form(IODevice, StartLine, []) . See also: parse_form/2 . quick_parse_form(Dev::IODevice, L0::StartLine, Options) -> {ok, Form, LineNo} | {eof, LineNo} | {error, errorinfo(), LineNo} Types IODevice = pid() StartLine = integer() Options = [term()] Form = syntaxTree() (see module erl_syntax) LineNo = integer() Similar to parse_form/3 , but does a more quick-and-dirty processing of the code. See quick_parse_file/2 for details. See also: parse/3 , parse_form/3 , quick_parse_form/2 . tokens_to_string(Tokens::[term()]) -> string() Generates a string corresponding to the given token sequence. The string can be re-tokenized to yield the same token list again. AUTHORS
Richard Carlsson <richardc@it.uu.se > syntax_tools 1.6.7 epp_dodger(3erl)
All times are GMT -4. The time now is 11:37 PM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy