![]() |
|
|
google unix.com
|
|||||||
| Forums | Register | Forum Rules | Links | Albums | FAQ | Members List | Calendar | Search | Today's Posts | Mark Forums Read |
| Shell Programming and Scripting Post questions about KSH, CSH, SH, BASH, PERL, PHP, SED, AWK and OTHER shell scripts and shell scripting languages here. |
More UNIX and Linux Forum Topics You Might Find Helpful
|
||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| searching and storing unknown number of lines based on the string with a condition | swamymns | Shell Programming and Scripting | 7 | 05-13-2008 02:02 AM |
| replacing new lines in all files of a directory containing old lines | rooster005 | Shell Programming and Scripting | 1 | 03-25-2008 03:38 PM |
| How to count lines - ignoring blank lines and commented lines | kthatch | UNIX for Dummies Questions & Answers | 6 | 05-25-2007 02:21 AM |
| Moving next 2 lines contents to previous lines | Amruta Pitkar | Shell Programming and Scripting | 8 | 04-26-2007 07:09 AM |
| sed searching across lines | miechu | Shell Programming and Scripting | 11 | 10-03-2006 05:27 AM |
|
|
LinkBack | Thread Tools | Search this Thread | Rate Thread | Display Modes |
|
||||
|
lines searching >>
hi guys! I`ll really appreciate your help. The situation is: i have a log file, and i need to get the needed lines from it. Code:
linecount=$(cat -n http.log | grep ALERT | awk '{print $1}' | wc -l)
lines=$(cat -n http.log | grep ALERT | awk '{print $1}')
1-string gets the number of found lines 2-string gets the string numbers What I need is to make script to get next 5 lines after each found $lines. For example: echo $lines 287 309 331 so the needed strings are 287-292, 309-314, 331-336. my idea was to make something like: Code:
cat -n http.log | grep ALERT | awk '{print $1}' > lines # to record needed string numbers in file
for i in $(seq 1 $linecount); do
let line$i=$(sed -n "$i" p lines) # to define each line number as variable :D i know that`s ugly
sed -n 'line$ip;line$i+1p;line$i+2p;...' http.log # that`s the ugliest ever, and that doesn`t work. Any suggestions?
done
it would be great if someone could show a quick solution of how to do that or just some suggestions! Thanks! Last edited by neverhood; 01-18-2009 at 04:34 AM.. |
| Bookmarks |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|