I have a text file
demo.txt like below.
This is a line with id (9) This (8) is another line with id (10) This is a line with id too 11 This line does nothing
The file has some lines with id scattered randomly. The id pattern is number with parenthesis.
My job is to find the largest id in this file so that I know what the next id is when adding a new line.
My previous work
ack-grep demo.txt -o --match '\(\d+\)' | sort -r | head -n 1
The result is
(9) but not
(10) as my expectation. I think the reason is
sort regards the output as text because they have parenthesis.
The question is: How can I output only the number from
grep for later sorting but still matching the pattern(parenthesis in my example)?
Thanks a lot!