I'm using the following code to extract the lines(and redirect them to a txt file) after the pattern match. But the output is inclusive of the line with pattern match.
Which option is to be used to exclude the line containing the pattern?
Does your server support the -A flag on grep? That might be a neater solution:-
grep -A10 pattern file
Maybe I've missed the point. If you want all lines after a certain point, perhaps you could use grep to get the record number and then tail to get you the output you need:-
#!/bin/ksh
grep -n pattern file|tr ":" " "|read line xxx # Get the interesting line number
wc -l file | read total xxx # Get total lines
((readrecs=$total-$line)) # Work out how many lines from end to read
tail -$readrecs file
All you need is egrep -A piped into grep -v. Set the -A for the number of rows that you want to see after the row you are looking for and use grep -v to filter the row that you were looking for. you don't need sed or a for loop.
$ egrep -A1 "alias top" .bashrc
alias top='xtitle Processes on $HOST && top'
alias make='xtitle Making $(basename $PWD) ; make'
$ egrep -A1 "alias top" .bashrc | grep -v "alias top"
alias make='xtitle Making $(basename $PWD) ; make'
My server doesn't support -A on grep. Besides, the statement that I've written is already a complex one and I want to use sed as part of multiple piped commands. Using 3-4 lines of code there would not be feasible.
---------- Post updated at 02:04 AM ---------- Previous update was at 01:51 AM ----------
Made it work somehow.. although still looking for a better solution. Here's what I am using for the time being:
So have the requirements changed? This will remove the line that contains the pattern plus the line after that line, so effectively the first two lines.....