To catch the start of a sequence from a file
awk, bash, grep, sed
Solution
awk 'BEGIN {p=1} p==1 {print $1;p=0} $0~/{/ {p=1}'
Output:
125
566
700
Given the file format above, you could use awk and a variable/flag to keep track on when you find an opening `{`
Problem
I have a text file which goes like this : ``` 125 126 127 { 566 567 568 569 # blah blah 570 { #blah blah 700 701 { ``` The numbers are left aligned and the pattern is always the same in the sense increasing and a curly braces at the end .I need to catch just the starting number .The braces are always found and limited to the sequence end .The start of the file is as shown starting with '125'. In short I need : ``` 125 566 700 ``` What I have come up with : ``` grep -A1 '{' | grep -v '{' | grep -oE '(^[0-9]+?)' ``` but this omits '125' but I overcame by appending a newline at the head and inserting a `{` . I hope to reduce this into a single regex. Suggestions and better algorithms are welcome