I want to split txt file on string "Template[0]", "Template[1]" etc.
The command below works until "Template[10]"
csplit -k cert_templates.txt '/Template\[[0-9]\]:/' {*}
I tried those but they did'nt work
csplit -k cert_templates.txt '/Template\[([0-9] )\]:/' {*}
csplit -k cert_templates.txt '/Template\[[0-9] \]:/' {*}
This works for "Template[10]" until "Template[100]"
csplit -k cert_templates.txt '/Template\[[0-9][0-9]\]:/' {*}
What regex should i use to work with undefined number of digits?
Any help would be much appreciated.
CodePudding user response:
This regex will suffice: ^\d $
To break this down, the \d
means any digit and the
means one or more.
CodePudding user response:
The regex flavor used by this csplit
requires that ' ', if it is to match a sequence of 1 or more, is preceded by a backslash, i. e. Template\[[0-9]\ \]
.