I have following data extracted from the MySQL database to create labels.
BREAK Name:RAJ Company:ABC Order Number:101 Order Details: Item1 Item20 Item3 BREAK Name:RAJ Company:ABC Order Number:101 Order Details: 2 x Item1 2 x Item2 2 x Item3 BREAK Name:RAJ Company:ABC Order Number:101 Order Details: 5 x Item4 5 x Item5 5 x Item2
I wrote some code to find the position of BREAK in PHP and it can generate lines number like below.
2 14 26 36
I want a file for the contents that are between line 2 and 14 in one file and 26 to 36 in one file. I am working in php and tried using sed from shell_exec function however if I read this output and generate sed command, I don’t get first 2 number together.
What I am expecting is below.
sed -n 2,14p file1.txt sed -n 26,36p file2.txt
Any suggestion either in php or shell script?
Use array_slice() for getting ranges in an array.
My solution is very hard coupled to your requirements, meaning every first line is a starting range number and the following the end range.
But it would be a lot easier to do it automatically on your source file/text/string (?) directly, if this is possible.