Sponsored Content
Top Forums Shell Programming and Scripting Script to capture string in a log file Post 302920221 by pratikgupta123 on Wednesday 8th of October 2014 07:54:12 AM
Old 10-08-2014
I am not having access to a machine right now so cant test a code but my logic would be something like this:

1. Loop on the file line by line
2. Add the line to an array by default
3. Continue adding the lines until you reach a line that starts with date.
4. At this point analyze if the existing lines in the array have exception word in it or not
5. If yes then print it to output file and flush the array and add next line to it
5. If no then flush the array and add next line to it
 

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

capture nohup log file

Hi, I am running my script using nohup, but I am not able to capture the log file for that process could naybody please help... Here is what I am doing.... nohup ./script & 1>/home/user1/log.txt but I am not able to capture the log.....Is there anyother way I can capture the log... (2 Replies)
Discussion started by: mgirinath
2 Replies

2. Shell Programming and Scripting

Capture the command run in the log file

Hi , I have seen some log files where they have captured the command that is being executed, comments present in the scripts and the out put of the command as well, through scripts. could any one of you please let me know how do i do that? Thanks in advance. Cheers, Waseem (4 Replies)
Discussion started by: ahmedwaseem2000
4 Replies

3. Shell Programming and Scripting

capture output of file and send last string thereof to new file

Hello, If I run a program from within shell, the output is displayed in the command line terminal. Is there a way I can capture that output and choose only the very last string in it to send it to a new file? Thank you (6 Replies)
Discussion started by: Lorna
6 Replies

4. Shell Programming and Scripting

How to capture output to log file

Hi I have a script that will run multiple unix & sql commands. I want to see the output as well as capture it to a log file for further analysis. Is there an easy way to do that instead of adding "tee -a logfile" on everyline or even on the execute line (i.e. script | tee -s logfile). Thanks (1 Reply)
Discussion started by: nimo
1 Replies

5. Shell Programming and Scripting

Need to capture certain text from a string in a different file

Hi, I wanted to know how i could accomplish this in a script using ksh. Lets say there is a file called test.dat and it has a certain input like below : . . Hi = 56 Hi = 67 . . 1 record(s) selected Now i need to capture the numbers after the = sign and store them in a... (3 Replies)
Discussion started by: Siddarth
3 Replies

6. Shell Programming and Scripting

Capture all error message in Log file and send the Log file by email

Hi I have a requirement to write a script to capture all errors in a Logfile and send the file in email. If there is any error occurred the subject of email will be ERROR , If there are no error occurred the subject of email will be SUCCESS. So I created a Log file and put the Appropriate... (2 Replies)
Discussion started by: dgmm
2 Replies

7. Shell Programming and Scripting

Shell script to capture ORA errors from Alert Log

Hi, as the title says, I am after a simple script, which will open the Alert log from an 11.2.0.1 Linux environment and mail the error message and description to a recipient email address. I can then schedule this job via cron and let it run every 15 minutes. I have searched online... (16 Replies)
Discussion started by: jnrpeardba
16 Replies

8. Shell Programming and Scripting

How to capture a string enclose by a pattern within a file?

Hi all, My file :test.txt just like this: ........................... From: 333:123<sip:88888888888@bbbb.com To: <sip:123456@aaaaa.com ......................... I want a script to capture the string between sip: & @ Expect output: 88888888888 123456 Please help! (4 Replies)
Discussion started by: Alex Li
4 Replies

9. Shell Programming and Scripting

String capture from ip file

Dear All From below mention input file I want op file as mention. Kindly help. IP file: "BSCGNR4_IPA17_C" 329 140119 0717 RXOCF-105 KJO001_BASC_NG AC FAULTY DG ON DOOR OPEN Needed OP: 140119 0717 KJO001_BASC_NG AC FAULTY DG ON DOOR OPEN Note that string mark in red as variable in... (3 Replies)
Discussion started by: jaydeep_sadaria
3 Replies

10. Shell Programming and Scripting

Help on script to capture info on log file for a particular time frame

Hi I have a system running uname -a Linux cmovel-db01 2.6.32-38-server #83-Ubuntu SMP Wed Jan 4 11:26:59 UTC 2012 x86_64 GNU/Linux I would like to capture the contents of /var/log/syslog from 11:00AM to 11:30AM and sent to this info via email. I was thinking in set a cron entry at that... (2 Replies)
Discussion started by: fretagi
2 Replies
FILE(3) 								 1								   FILE(3)

file - Reads entire file into an array

SYNOPSIS
array file (string $filename, [int $flags], [resource $context]) DESCRIPTION
Reads an entire file into an array. Note You can use file_get_contents(3) to return the contents of a file as a string. PARAMETERS
o $filename - Path to the file. Tip A URL can be used as a filename with this function if the fopen wrappers have been enabled. See fopen(3) for more details on how to specify the filename. See the "Supported Protocols and Wrappers" for links to information about what abilities the various wrappers have, notes on their usage, and information on any predefined variables they may provide. o $flags - The optional parameter $flags can be one, or more, of the following constants: o FILE_USE_INCLUDE_PATH - Search for the file in the include_path. o FILE_IGNORE_NEW_LINES - Do not add newline at the end of each array element o FILE_SKIP_EMPTY_LINES - Skip empty lines o $context - A context resource created with the stream_context_create(3) function. Note Context support was added with PHP 5.0.0. For a description of contexts, refer to "Streams". RETURN VALUES
Returns the file in an array. Each element of the array corresponds to a line in the file, with the newline still attached. Upon failure, file(3) returns FALSE. Note Each line in the resulting array will include the line ending, unless FILE_IGNORE_NEW_LINES is used, so you still need to use rtrim(3) if you do not want the line ending present. Note If PHP is not properly recognizing the line endings when reading files either on or created by a Macintosh computer, enabling the auto_detect_line_endings run-time configuration option may help resolve the problem. CHANGELOG
+--------+----------------------------+ |Version | | | | | | | Description | | | | +--------+----------------------------+ | 4.3.0 | | | | | | | file(3) became binary safe | | | | +--------+----------------------------+ EXAMPLES
Example #1 file(3) example <?php // Get a file into an array. In this example we'll go through HTTP to get // the HTML source of a URL. $lines = file('http://www.example.com/'); // Loop through our array, show HTML source as HTML source; and line numbers too. foreach ($lines as $line_num => $line) { echo "Line #<b>{$line_num}</b> : " . htmlspecialchars($line) . "<br /> "; } // Another example, let's get a web page into a string. See also file_get_contents(). $html = implode('', file('http://www.example.com/')); // Using the optional flags parameter since PHP 5 $trimmed = file('somefile.txt', FILE_IGNORE_NEW_LINES | FILE_SKIP_EMPTY_LINES); ?> NOTES
Warning When using SSL, Microsoft IIS will violate the protocol by closing the connection without sending a close_notify indicator. PHP will report this as "SSL: Fatal Protocol Error" when you reach the end of the data. To work around this, the value of error_reporting should be lowered to a level that does not include warnings. PHP can detect buggy IIS server software when you open the stream using the https:// wrapper and will suppress the warning. When using fsockopen(3) to create an ssl:// socket, the developer is responsible for detecting and suppressing this warning. SEE ALSO
readfile(3), fopen(3), fsockopen(3), popen(3), file_get_contents(3), include(3), stream_context_create(3). PHP Documentation Group FILE(3)
All times are GMT -4. The time now is 12:41 PM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy