Search specific string logfile specific date range


 
Thread Tools Search this Thread
Top Forums UNIX for Dummies Questions & Answers Search specific string logfile specific date range
# 1  
Old 02-26-2015
Search specific string logfile specific date range

Hi,

I have logfile like this..
Code:
=== 2014-02-09 15:46:59,936 [c-22] INFO  RequestContext - URL: '/eyisp/sc/skins/EY/images/pickers/comboBoxPicker_Over.png', User-Agent: 'Mozilla/5.0 (Windows NT 6.1; WOW64; Trident/7.0; rv:11.0) like Gecko': Unsupported with Accept-Encoding header
=== 2015-02-09 15:46:59,937 [c-22] INFO  Download - done streaming: /usr/share/apache-tomcat-8.0.12/webapps/ROOT/eyisp/sc/skins/EY/images/pickers/comboBoxPicker_Over.png
Server Console List of Data :- 5
=== 2015-02-09 15:47:08,792 [c-27] INFO  Download - Returning 304: Not modified on conditional get of: /usr/share/apache-tomcat-8.0.12/webapps/ROOT/eyisp/sc/skins/EY/images/Progressbar/progressbar_h_empty_stretch.gif
=== 2015-02-10 05:47:08,793 [c-14] INFO  Download - Returning 304: Not modified on conditional get of: /usr/share/apache-tomcat-8.0.12/webapps/ROOT/eyisp/sc/skins/EY/images/Progressbar/progressbar_h_empty_end.gif
=== 2015-02-10 05:47:08,793

I am using below script and It should search for the string "Download"

Code:
#!/bin/bash
        search="Download"
        logfile=/home/kudos/hari/logfn.txt
        str_output=""
        start_year=2014
        start_month=02
        start_day=9
        end_year=2015
        end_month=03
        end_day=10
                while [ $start_year -lt $end_year ];do
                while [ $start_month -lt $end_month ];do
                while [ $start_day -lt $end_day ];do
                        str_output+="$(grep $start_year-$start_month-$start_day $logfile|grep $search && printf '\n' )"
                        ((start_day++))
                        [ $start_day -gt 31 ] && start_day=1 && ((start_month++))
                                done
                                ((start_month++))
                        [ $start_month -gt 12 ] && start_month=1 && ((start_year++))
                                done
                                ((start_year++))
                        [ $start_year -gt $(date +'%Y') ] && break
                                done
         printf "${str_output}\n"

I saved as SCRIPT.sh, I have executed the script the I got the following result as empty.Could you suggest on this
Code:
[root@test hari]# ./SCRIPT.sh
[root@test hari]#

Thanks in an advace,
Regards,
kishore.

Last edited by Don Cragun; 02-26-2015 at 07:12 AM.. Reason: Add CODE tags; correct some text (s/above/below/).
# 2  
Old 02-26-2015
Not sure if you post the complete script? I am not seeing closing loops any.

Another quick check is, you have zero padded "start_day" in file but you are searching for single digit.

Second check is, var+=, I don't think is a shells specific syntax.
# 3  
Old 02-26-2015
Actuall this sample code in UNIX for Dummies Questions & Answers dated 03-27-14

<SPAN class=smallfont> thread name is <SPAN class=smallfont>

---------- Post updated at 07:11 AM ---------- Previous update was at 07:10 AM ----------

thread ne me is "Search for a specific String in a log file for a specific date range"
# 4  
Old 02-26-2015
Quote:
Originally Posted by clx
Second check is, var+=, I don't think is a shells specific syntax.
It is valid syntax for Bash
Code:
str="Hello"
$ str+=" "
$ str+="World"
$ echo $str
Hello World
$

Also works in the Korn shell
This User Gave Thanks to fpmurphy For This Post:
# 5  
Old 02-27-2015
However I checked before responding but its not working for me. Is it version specific?

Code:
$ str="Hello"
$ str+=" "
bash: str+= : command not found
$ str+="World"
bash: str+=World: command not found
$

# 6  
Old 02-27-2015
Not sure. It certainly works in all recent versions of both shells.
# 7  
Old 02-28-2015
Quote:
Originally Posted by clx
However I checked before responding but its not working for me. Is it version specific?

Code:
$ str="Hello"
$ str+=" "
bash: str+= : command not found
$ str+="World"
bash: str+=World: command not found
$

Yes, it is shell specific and version specific.

You still haven't told us what shell you're using... although it is some version of bash from the diagnostics.

It is in ksh version 93u+ 2012-08-01, but it is not available in any ksh88 and it is not mentioned in the 1995 edition of the book The New Korn shell Command and Programming Language (so it is not available in some earlier versions of ksh93).

I don't know when it was added to bash either.

Note that with any shell based on Bourne shell syntax, you could replace the above with:
Code:
$ str="Hello"
$ str="$str "
$ str="${str}World"
$ echo "$str"
Hello World
$ 


Last edited by Don Cragun; 02-28-2015 at 02:57 AM.. Reason: Note that unknown bash version is used; add portable way to get desired results.
This User Gave Thanks to Don Cragun For This Post:
 
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. UNIX for Beginners Questions & Answers

How to use a grep search to search for a specific string within multiple directories?

Lets say I have a massive directory which is filled with other directories all filled with different c++ scripts and I want a listing of all the scripts that contain the string: "this string". Is there a way to use a grep search for that? I tried: grep -lr "this string" * but I do not... (3 Replies)
Discussion started by: Circuits
3 Replies

2. UNIX for Dummies Questions & Answers

Need to search specific string in a log

Hi, I have a log file containing below data 12/3/14 12:43:59 AM WIT |Performance threshold: elapsed time = 3152... (5 Replies)
Discussion started by: csm231
5 Replies

3. UNIX for Dummies Questions & Answers

Search for a specific String in a log file for a specific date range

Hi, I have log file which rolls out every second which is as this. HttpGenRequest - -<!--OXi dbPublish--> <created="2014-03-24 23:45:37" lastMsgId="" requestTime="0.0333"> <response request="getOutcomeDetails" code="114" message="Request found no matching data" debug="" provider="undefined"/>... (3 Replies)
Discussion started by: karthikprakash
3 Replies

4. Shell Programming and Scripting

Replace specific column range in a non-delimited file with a string!

Hi All, I will need an help with respect to replacing a range of columns on a non-delimited file using a particular string pattern. Say file input is MYNUMBERD000000-BAN CHUE INSNTS ** N+ MYAREDSDD000000+BAN CHUE INSNTS ** N+ MYDERFFFSD00000-GIR PENT - ACH ** ... (5 Replies)
Discussion started by: navojit dutta
5 Replies

5. Shell Programming and Scripting

Urgent request to consider:Search specific name in a file and fetch specific entries

Hi all, I have 2 files, One file contain data like this FHIT CS CHRM1 PDE3A PDE3B HSP90AA1 PTK2 HTR1A ESR1 PARP1 PLA2G1B These names are mentioned in the second file(Please see attached second file) as # Drug_Target_X_Gene_Name:(Where X can be any number (1-1000) (1 Reply)
Discussion started by: manigrover
1 Replies

6. Shell Programming and Scripting

Search for a specific data in a file based on a date range

Hi, Currently I am working on a script to automate the process of converting the log file from binary into text format. To achieve this, partly I am depending on my application’s utility for this conversion and the rest I am relying on shell commands to search for directory, locate the file and... (5 Replies)
Discussion started by: svajhala
5 Replies

7. UNIX for Dummies Questions & Answers

pattern search using grep in specific range of files

Hi, I am trying to do the following: grep -l <pattern> <files to be searched for> In <files to be searched for> , all files should of some specific date like "Apr 8" not all files in current directory. I just to search within files Apr 8 files so that it won't search in entire list of... (2 Replies)
Discussion started by: apjneeraj
2 Replies

8. Shell Programming and Scripting

Search a specific string

Hi, I have following requirement. Pls suggest. To search a string in a file which is combination of character and number(always 9 digit, but numeric). if found then caputure the exit return code as 0 else 1 , if 0 then next job can be triggerd. If exit code is 1, should return a failure... (10 Replies)
Discussion started by: zooby
10 Replies

9. UNIX for Dummies Questions & Answers

Coping Files for a specific date range

Hi, we have file name appended by date in yymmdd format .. ex: abc090101.dat I need to copy all the files between abc090101 to abc090331.. could you plz help me.. Thanks. (1 Reply)
Discussion started by: kolariya4u
1 Replies

10. Shell Programming and Scripting

Get Data Between a specific Date Range from logs

I need to extract data from logs for a mentioned date range..Its quite urgent can anyone help me out with it..its to be written in unix..just thought its better to specify.. (4 Replies)
Discussion started by: sankasu
4 Replies
Login or Register to Ask a Question

Featured Tech Videos