Visit Our UNIX and Linux User Community


Script to extract line from logfile


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Script to extract line from logfile
# 15  
Old 09-27-2009
Yeah, but then I'm always shooting for the lowest common denominator. And then there is that whole at/cron thing that is part of Garry's requirement Smilie

There are always more than one way to get'er done Smilie
# 16  
Old 10-02-2009
Hi JP,

The script removed GuestUser string from all the logfiles in the path.
I tried the following -

awk -f log.awk gtest/svtaree/*
awk -f log.awk gtest/*/*

And the output on the screen was blank

Few questions -
1. Will the script work if the logfiles are located in different path.
2. Some of the logfiles are in tar and zip format.
3.The script should remove the GuestUser string from all the original logfile and copy to test.txt.

And sorry for troubling you dear.Was going thru a very hectice schedule and was only seeing to the word cygwin and not trying to understand it.

Thanks again,
Garry
# 17  
Old 10-02-2009
A few things:
  1. The script is expecting a list of paths to the log file as specified in your original problem definition. Your wildcard path name will match to things other than the log file name you first defined. It will work those files too. That may not be somethnig you want.
  2. Only error messages are output to the screen. No message means no errors.
  3. There should be a file named test.txt left in the same directory as the log file containing the removed lines.
  4. The script is not designed to process compressed or archived files.

Is the test.txt file not being created? If there were other files that weren't log files of the type you specified originally, there may no text.txt file and the file that you did give it via the wildcarding might be modified.
# 18  
Old 10-03-2009
Hi JP,

The logfile name is access_09.06.09.log
There is no other files in the server path except for logfiles.
And I did search for the test.txt file and it is not created

Thanks,
Garry
# 19  
Old 10-03-2009
The script does not work because you changed the rules. The script expects the log file to be logfile_systemdat.log, as you originally specified. And it only expects to have a list of paths to these log files on the command line. Again, this was part of your original spec. The file test.txt is not created because the log file name is not logfile_systemdat.log.

Given that these forums are meant to give guidance rather than be a source of production quality code and your stated urgency, I suggest you hire a consultant to complete your project.

The script I wrote for you will work for your original spec and can be used as a basis for your changing requirements.
# 20  
Old 10-04-2009
Hi JP,

As you are right I did metion the logfile_systemdate.log ( meaning name in string and then appended by the current system date dot.log)

Apologies if I have confused you.
# 21  
Old 10-04-2009
Try changing

Code:
sub(/logfile_systemdat.log/, "test.txt", FILELOG)


to

Code:
sub(/\/*\.log$/, "/test.txt", FILELOG)

This should cause the test.txt file to be created. If there are more that one log file per path then you will only have a test.txt for the last log file processed.

Previous Thread | Next Thread
Test Your Knowledge in Computers #588
Difficulty: Easy
A linear search algorithm is also known as sequential search.
True or False?

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Logfile monitoring with logfile replacement

Bonjour, I've wrote a script to monitor a logfile in realtime. It is working almost perfeclty except for two things. The script use the following technique : tail -fn0 $logfile | \ while read line ; do ... some stuff done First one, I'd like a way to end the monitoring script if a... (3 Replies)
Discussion started by: Warluck
3 Replies

2. Shell Programming and Scripting

Extract the last 10 minutes from logfile

Any better way to extract the last 10 minutes from logfile? Dec 18 09:41:18 aaa Dec 18 09:46:29 aa Dec 18 09:48:39 vvv Dec 18 09:48:54 bbb Dec 18 09:54:47 bbb Dec 18 09:55:33 fcf Dec 18 09:55:38 ssdf Dec 18 09:57:58 sdsds Dec 18 09:58:10 sdsd Dec 18 10:00:50 sdsd Dec 18... (5 Replies)
Discussion started by: timmywong
5 Replies

3. Shell Programming and Scripting

Unique line from logfile

Hi Team, Pls help me in fixing this problem. I have file called ORA_FILE.log Please find the log in that below: ************************ ORA-04061: existing state of package body "MST.ONE_PACKAGE" has been invalidated ORA-04065: not executed, altered or dropped package body... (2 Replies)
Discussion started by: indira_s
2 Replies

4. Shell Programming and Scripting

Extract three substrings from a logfile

I have a log file like below. 66.249.73.11 - - "UCiZ7QocVqYAABgwfP8AAHAA" "US" "Mediapartners-Google" "-" www.mahashwetha.com.sg "GET... (2 Replies)
Discussion started by: Tuxidow
2 Replies

5. Shell Programming and Scripting

HELP: Shell Script to read a Log file line by line and extract Info based on KEYWORDS matching

I have a LOG file which looks like this Import started at: Mon Jul 23 02:13:01 EDT 2012 Initialization completed in 2.146 seconds. -------------------------------------------------------------------------------- -- Import summary for Import item: PolicyInformation... (8 Replies)
Discussion started by: biztank
8 Replies

6. Shell Programming and Scripting

Search for a pattern,extract value(s) from next line, extract lines having those extracted value(s)

I have hundreds of files to process. In each file I need to look for a pattern then extract value(s) from next line and then search for value(s) selected from point (2) in the same file at a specific position. HEADER ELECTRON TRANSPORT 18-MAR-98 1A7V TITLE CYTOCHROME... (7 Replies)
Discussion started by: AshwaniSharma09
7 Replies

7. Shell Programming and Scripting

get the fifth line of a text file into a shell script and trim the line to extract a WORD

FOLKS , i have a text file that is generated automatically of an another korn shell script, i want to bring in the fifth line of the text file in to my korn shell script and look for a particular word in the line . Can you all share some thoughts on this one. thanks... Venu (3 Replies)
Discussion started by: venu
3 Replies

8. Shell Programming and Scripting

Logfile - extracting certain lines to concatenate into 1 line

I've got a log file from automatic diagnostic runs. The log file is appended to each time an automatic log is run. I'd like to just pull certain lines from each run in the log file, and concatenate them into 1 comma delimited line (for export into excel or an html table). Each diagnostic run... (3 Replies)
Discussion started by: BecTech
3 Replies

9. Shell Programming and Scripting

Need to extract specific pattern from logfile

Log File: Attempting to contact (DESCRIPTION=(SOURCE_ROUTE=OFF)(ADDRESS_LIST=(ADDRESS=(PROTOCOL=TCP)(HOST=hostname1.com)(PORT=1521)))(CONNECT_DATA=(SID=database1)(SRVR=DEDICATED))) Attempting to contact... (2 Replies)
Discussion started by: techychap
2 Replies

10. UNIX for Advanced & Expert Users

Script to Extract the line from File with specified offset

Hi All, I need to extract only XML details from large log file which may contain other unwanted junk details. For example, our xml will be start as <OUTBOUND_MESSAGE .....> and ends with </OUTBOUND_MESSAGE>. I want to extract only lines between these start and end tag (Including these tags)... (5 Replies)
Discussion started by: thinakarmani
5 Replies

Featured Tech Videos