how to sed with tail


 
Thread Tools Search this Thread
Top Forums UNIX for Dummies Questions & Answers how to sed with tail
# 1  
Old 08-29-2005
how to sed with tail

hi,

I am searching error and exception in my log and >> to report file,
my code is :

sed -n '/[eE][rR][rR][oO][rR]/p;/[eE][xX][cC][eE][pP][tT][iI][oO][nN]/p' $ARIBA_LOG_DIR/MyLog.txt >> $LOG_ERR_REP

I need to report avove 5 line, that line and bellow 5 line..

what change is required in my code?
# 2  
Old 08-30-2005
Using the shell, i'd do something convoluted like this
Code:
$ cat ./redlotus.sh
#!/bin/ksh

matchfile="redlotus.txt"

matches=`echo "${line}" | egrep -in "Error|Exception" ${matchfile}`
echo "${matches} " | while read line; do
   lineno=`echo "${line}" | cut -d: -f1`
   match=`echo "${line}" | cut -d: -f2`
   echo "Match found - line ${lineno} - ${match}"
   minline=$(( lineno - 5 ))
   [[ "$(( lineno - 5 ))" -lt 1 ]] && minline=1
   sed -n "$minline,$(( lineno - 1 ))p" ${matchfile}
   sed -n "$lineno p" ${matchfile}
   sed -n "$(( lineno + 1 )),$(( lineno + 5 ))p" ${matchfile}

   # note we could just do
   # sed -n "$minline, $((lineno + 5))p" ${matchfile}
   # but i've left this as-is to show you how to grab the previous, and the
   # next, five lines....
done
exit 0

No doubt, there is a far easier way (using -C option to GNU (e)grep for example)....

Cheers
ZB
 
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. UNIX for Beginners Questions & Answers

Tail -f Command help

Hi Team, Can anyone help me here: I have to access server logs via putty and these logs file is a trailing file (continously updating) with ERROR and WARNINGS... I need to know if I can pull this trailing file to a local drive so that I can do some higlighting on some keywords through Notepad... (13 Replies)
Discussion started by: jitensetia
13 Replies

2. Shell Programming and Scripting

How to tail sed and awk in one line?

Hello, I am trying to create an iptables script with tail ,sed and awk. 1st Request: Search keyword "secret" in access.log file 2nd Request: Get first column matching lines (ip address) 3rd Request: Save it to a file This is what I did so far: grep.sh #!/bin/bash while true; do tail... (23 Replies)
Discussion started by: baris35
23 Replies

3. Shell Programming and Scripting

Tail +

because the tail +2 on the first line gives me the file name pomga I do not want anything like what I miss tail +2 ejemplo.txt ouput ==> ejemplo.txt <== 1 2 3 4 5 6 7 8 9 10 (2 Replies)
Discussion started by: tricampeon81
2 Replies

4. UNIX for Dummies Questions & Answers

What should be precedence of using awk, sed, head and tail in UNIX?

Hi All, I am new to unix. In this forum some days back, I have read something like below: 1) Do not use perl if awk can do your work. 2) Do not use awk if sed can do your work. . . . I do not re-collect the whole thing. I think it is good to know the precedence of using these... (2 Replies)
Discussion started by: Prathmesh
2 Replies

5. Shell Programming and Scripting

Joining multiple files tail on tail

I have 250 files that have 16 columns each - all numbered as follows stat.1000, stat.1001, stat.1002, stat.1003....stat.1250. I would like to join all 250 of them together tail by tail as follows. For example stat.1000 a b c d e f stat.1001 g h i j k l So that my output... (2 Replies)
Discussion started by: kayak
2 Replies

6. UNIX for Advanced & Expert Users

sed one liner simialr to tail command

Can anyone explain the below sed oneliner? sed -e ':a' -e '$q;N;11,$D;ba' It works same as tail command. I just want to know how it works. Thanks (1 Reply)
Discussion started by: pandeesh
1 Replies

7. Shell Programming and Scripting

tail issue!

Hi, I had few scripts which were running fine on linux: uname -a Linux ######### 2.6.9-89.ELsmp #1 SMP Mon Apr 20 10:33:05 EDT 2009 x86_64 x86_64 x86_64 GNU/Linux from some front end application. Recently there was a migration of this application on some other linux m/c: uname -a... (4 Replies)
Discussion started by: dips_ag
4 Replies

8. Shell Programming and Scripting

tail -f

I am trying to extract a particular line from a.log which keeps appending every sec and output that into a newfile b.log which should append itself with filtered data received from a.log I tried tail -f a.log |grep fail| tee -a b.log nothing in b.log tail -f a.log |grep fail >>b.log ... (4 Replies)
Discussion started by: wannalearn
4 Replies

9. Shell Programming and Scripting

Tail??

Hello all, I have search the forum and could not find an answer...Here is what I am trying to do. Every 15 minutes, a script send uptime output to a logfile (dailylog.log), that file contains lines like the one below: 11:21am up 44 days, 19:15, 1 user, load average: 0.00, 0.02, 0.03 ... (7 Replies)
Discussion started by: qfwfq
7 Replies

10. Shell Programming and Scripting

using tail -f

Working in HP-UX 10.20. I eventually want to write a bourne shell script to handle the following problem, but for now I am just toying with it at the command line. Here's what I am basically trying to do: tail -f log_X | grep n > log_Y I am doing a tail -f on log_X . Once it sees "n", I... (6 Replies)
Discussion started by: cdunavent
6 Replies
Login or Register to Ask a Question