Saturday 15 August 2015

awk - How to filter different files from one file -


It says that I want different files starting from "process" with "next" process For example, input file

 process = 0 we like questions which can be answered, not just discussed, provide details clearly and just write. If your question is this About the website, ask instead on the meta. Infection = 1 We like questions which can be answered, just discuss, provide details, write clearly and clearly If your question is about this website, it Puchia.prkriya = 2 Meta we can all have questions prefer that answer is, not only to discuss Kikvivrn, write clearly and simply. Your question is about this website, instead of asking it on the meta. 

Expected output should be in the file

 process = 0 We like questions which can be answered, not just discussed. Clearly and just write. If your question is about this website then ask on the meta instead. 

must be in file_1

 process = 1 We like questions which can be answered, not just discussed. give details. Write clearly and simply if your question is about this website, then ask it on Meta. 

should be in file_2

 process = 2 We like questions which can be answered, not just discussed. give details. Write clearly and simply if your question is about this website, then ask it on Meta. 

This creates the file for each section and outputs text to them. If there is a text before the first "process", then it is placed in a file called "premble".

  awk -F '[=]' 'BEGIN {file = "preamble"} {if ($ 1 == "process") file = "file_" $ 2; Print & gt; & Gt; File} 'inputfile  

No comments:

Post a Comment