grepping log files


 
Thread Tools Search this Thread
Top Forums UNIX for Dummies Questions & Answers grepping log files
# 1  
Old 04-20-2011
grepping log files

I have a log file and I have two unique strings which represent the start and end of the text I want to obtain.

How can I get all the text inbetween this start string and the end string?

Thanks
# 2  
Old 04-20-2011
Code:
#!/bin/bash
# tested on bash 4
declare -i toggle=0
while read -r line
do
    case "$line" in
        *start*)
            toggle=1
            line="${line#start}"
            ;;
        *end*)
            toggle=0
            line="${line%end*}"
            ;;
    esac
    if [ $toggle -eq 1 ];then
        echo "$line"
    fi
done <file

# 3  
Old 04-20-2011
awk '/start_string/, /stop_string/' file
 
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Grepping only dates from a log file

Hi All, I have a log file where every line contains a date and some other data, i want to grep only the date from every line to a different file. Please help how to get this. Thanks in advance !! (25 Replies)
Discussion started by: nanz143
25 Replies

2. Shell Programming and Scripting

Performance issue in Grepping large files

I have around 300 files(*.rdf,*.fmb,*.pll,*.ctl,*.sh,*.sql,*.prog) which are of large size. Around 8000 keywords(which will be in the file $keywordfile) needed to be searched inside those files. If a keyword is found in a file..I have to insert the filename,extension,catagoery,keyword,occurrence... (8 Replies)
Discussion started by: millan
8 Replies

3. UNIX Desktop Questions & Answers

Move the files which is coming after grepping

Dear Friends, I am trying to move the files which are listing after greaping command. see the details below 1. When i am running the grep command $ grep -il 'Bufman' *.* fatal.log fatal_info.log it has listed some files now i want to move this files to any another locate so i am... (13 Replies)
Discussion started by: ripudaman.singh
13 Replies

4. Shell Programming and Scripting

Grepping large list of files

Hi All, I need help to know the exact command when I grep large list of files. Either using ls or find command. However I do not want to find in the subdirectories as the number of subdirectories are not fixed. How do I achieve that. I want something like this: find ./ -name "MYFILE*.txt"... (2 Replies)
Discussion started by: angshuman
2 Replies

5. Shell Programming and Scripting

grepping files and then renaming file

Hi, What is the easiest way to list a directory with 1000s of filenames, grep it for a certain sequence of numbers, and if found to rename the file by the value you are grepping. eg The file I am examining will looks like this: 1234 1224343 2324 244 35665 If I am examining a list... (1 Reply)
Discussion started by: mantis
1 Replies

6. Shell Programming and Scripting

Grepping log file

Dear All, I have a log file that is dislpayed as: <msg time='2009-10-14T05:46:42.580+00:00' org_id='oracle' comp_id='tnslsnr' type='UNKNOWN' level='16' host_id='mtdb_a' host_addr='UNKNOWN' version='1'> <txt>14-OCT-2009 05:46:42 *... (19 Replies)
Discussion started by: x-plicit78
19 Replies

7. UNIX for Dummies Questions & Answers

grepping between files

Hi I have two files File 1 alias HOME =.. alias DATA = ${DATA}/runtime1/test alias SQL = ${DATA}/find1dir/test alias SQL1 = ${HOME}/sql/orcl alias SQL2 =... (2 Replies)
Discussion started by: ssuresh1999
2 Replies

8. Shell Programming and Scripting

grepping many values from same files

Hi All, I am having a script in which I am greping some values and storing them from files with .err and .log extensions. I feel I can do it better.But How? Below is my piece of code. oneerrors=`egrep -i -n "one" *.err *.log` twoerrors=`egrep -i -n "two" *.err *.log` ... (2 Replies)
Discussion started by: Sreejith_VK
2 Replies

9. Shell Programming and Scripting

Grepping the last 30 minutes of a log file...

I need to know if anyone can assist me on how to grab the last (we'll just say "x" minutes) of a log file. How do you tell the grep command without specifying an exact window of time? (So relative instead of absolute.) Thanks, Jon (2 Replies)
Discussion started by: jtelep
2 Replies

10. UNIX for Advanced & Expert Users

grepping lines out of files

Hi, I wonder if anyone can help me. I have a file with about 200 lines in it. I am wanting to set up a Count so that it picks out each line at turn and edits the line. However i am having trouble pulling out the specific line. I have a feeling it will be done somehow by a grep -n but what ever i... (2 Replies)
Discussion started by: mariner
2 Replies
Login or Register to Ask a Question