I need to grep through a file for a string and print the next ten lines to a file separating the lines with a , and save it as a csv file to open it as a XL file. The 10 lines should be on a sigle row in xl.
Input:
FindString
Line after string
Line after string
Line after string
Line after string
----100Lines
Line after string
FindString
Line after string
Line after string
Line after string
Line after string
----100Lines
Line after string
FindString
Line after string
Line after string
Line after string
Line after string
----100Lines
Output:
FindString,Line after string,Line after string,----,10th Line after string
FindString,Line after string,Line after string,----,10th Line after string
FindString,Line after string,Line after string,----,10th Line after string
I need to grep all the occurenses of FindString and print first 10 Lines for each occurence
A minor tweak to Shell_Life's solution which eliminates the need for paste:
sed -n '/MMM/{N;N;N;N;N;N;N;N;N;N;s/\n/,/g;p;}'
Something to bear in mind is that since this is not GNU sed, it may be necessary to qualify those N commands with $! (POSIX and most seds discard the pattern space if N tries to read a line when the EOF has been reached). However, this would only be necessary if the pattern matches a line that is followed by less than 10 lines and if the correct solution must print those lines. Given what we've been told, it's unknown whether or not this scenario is even a possibility.