Tag Info

New answers tagged

2

Now if the need to base output file names on file content can be removed, coreutils csplit may be faster at this than awk csplit file '/^Record[|]/' '{*}' This will create a set of files xx01, xx02 and so on. You can ignore the xx01 file since in your case it is going to be empty. Also note that csplit lets you configure the prefix (xx) and suffix (01, ...


2

Using GNU awk, you can try: gawk -v RS='Record[|]' -F'|' '$1{printf "%s%s", RT, $0 > $1}' file With Record| as the record separator, we can easily obtain each record. GNU awk's RS can be a regular expression (as in this case), and RT contains the text which matched this expression (Record|). With mawk, RT isn't available, so you can use printf ...



Top 50 recent answers are included