Input file.txt:Start of test case:test1abcDate is feb 12Start of test case:test2mnoDate is feb 13Start of test case:test3xyzDate is feb 14Desired output filestest1.txt:Start of test case:test1abcDate is feb 12test2.txt :Start of test case:test2mnoDate is feb 13test3.txt:Start of test case:test3xyzDate is feb 14
To split files Under linux Shell
text processing;awk;sed;grep
Use split:$ split -l 5 file.txt testThis will create the three files testa, testb and testc, each with 5 consecutive lines from the file file.txt.Alternatively, a solution in awk that writes to a new file whenever a new test case is found:$ awk '/^Start of test case:/ { c++ } { print >sprintf(test%d.txt, c) }' file.txt