Suppose I have a file in which there are lines matching same pattern but under different blocks how to write them in a separate file using grep/awk for example:
$ cat file.txt
spin 1
voltage current
spin 2
voltage current
$
I want to write spin 1 voltage current in a separate file "spi1.dat" and spin 2 voltage current in a separate file. How to I do this using grep/awk?