tags:

views:

34

answers:

3

Let as say I want different files starting from "process" till next "process. For example Input file

Process=0
We prefer questions that can be answered, not just discussed.
Provide details. Write clearly and simply.
If your question is about this website, ask it on meta instead.

Process=1
We prefer questions that can be answered, not just discussed.
Provide details. Write clearly and simply.
If your question is about this website, ask it on meta instead.
Process=2
We prefer questions that can be answered, not just discussed.
Provide details. Write clearly and simply.
If your question is about this website, ask it on meta instead.

Expected output File_0 should contain

Process=0
We prefer questions that can be answered, not just discussed.
Provide details. Write clearly and simply.
If your question is about this website, ask it on meta instead.

File_1 should contain

Process=1
We prefer questions that can be answered, not just discussed.
Provide details. Write clearly and simply.
If your question is about this website, ask it on meta instead.

File_2 should contain

Process=2
We prefer questions that can be answered, not just discussed.
Provide details. Write clearly and simply.
If your question is about this website, ask it on meta instead.
+2  A: 

Look at the csplit command in Linux. It splits text files at delimiters (which may be defined by a regular expression).

pavium
+1  A: 

use gawk/nawk(Solaris)

gawk -F"=" '/Process/{f=1;n=$2;print $0 > "File_"n;next}
f && /Process/{f=0} 
f&&NF{print $0 > "File_"n}
' file
ghostdog74
+2  A: 

This creates the files for each section and outputs the text to them. If there is text before the first "Process" then it is put in a file called "Preamble".

awk -F '[ =]' 'BEGIN {file="Preamble"} {if ($1 == "Process") file="File_"$2; print >> file}' inputfile
Dennis Williamson
Nice use of FS. It could be rewritten as: `awk -F '[ =]' 'BEGIN {file="Preamble"} $1 == "Process" {file="File_"$2} {print >> file}' inputfile`
glenn jackman