3

i want to split file by regular expression, i have file format as below

0|t| lorem ...
some text 
138|t| title 
some text 

if i execute egrep "[0-9]+\|t\|" file | wc -l it counts occurrence correctly but if i execute csplit filename /[0-9]+\|t\|/ then it says no match found and does not split file.

seems some issue with pipe in pattern but not able to figure out solution.

Jigar Parekh
  • 133
  • 4

1 Answers1

2

You must realize that csplit regexes are Basic Regular Expressions (BRE) and hence would not understand the + \| etc.

Just do this:

csplit yourfile '%^[0-9]*|t|%' '/^[0-9]*|t|/' '{*}'

Then look for files named xxNN in your current directory.

Dario Seidl
  • 2,346
  • 1
  • 20
  • 21
  • 1
    BRE: basic regular expressions. Like those supported by sed, grep, and awk: https://en.wikibooks.org/wiki/Regular_Expressions/POSIX_Basic_Regular_Expressions – Jason Harrison Jun 30 '22 at 17:52