how to use multiline records to split a large file but only a given number of time

  • Follow


well, not sure my title is clear
here is what i am trying to do:
i have a file like this:

titi
jkkk kkkk
tata


titi
jj
kkkl
tata

titi
kk
tata
....and so on
thus it always start by "titi" and end with "tata"

i would like to extract only twice these lines and send it to another
file, thus get this
titi
jkkk kkkk
tata


titi
jj
kkkl
tata


but also be able to fetch the following 4 repetitions of the block and
put it in another file...
well, suggestions are welcome
many thanks
bruno

0
Reply bruno.villoutreix (1) 3/11/2006 10:07:05 AM

Le Sat, 11 Mar 2006 02:07:05 -0800, bruno.villoutreix@univ-paris5.fr a
�crit�:

> well, not sure my title is clear
> here is what i am trying to do:
> i have a file like this:
> 
> titi
> jkkk kkkk
> tata
> 
> 
> titi
> jj
> kkkl
> tata
> 
> titi
> kk
> tata
> ...and so on
> thus it always start by "titi" and end with "tata"
> 
> i would like to extract only twice these lines and send it to another
> file, thus get this
> titi
> jkkk kkkk
> tata
> 
> 
> titi
> jj
> kkkl
> tata
> 
> 
> but also be able to fetch the following 4 repetitions of the block and
> put it in another file...
> well, suggestions are welcome
> many thanks
> bruno

 Are your records separated by blank lines like your sample suggests ?
 If so, use RS="" and count the records like 
 FNR<3 >fileone and FNR>3 >filetwo

$ awk 'FNR<3 {print $0,ORS> "___titione"}; 
       FNR>3 {print $0,ORS> "___tititwo"; } ' yourfile

 If you don't have blank lines, select by /titi/,/tata/ and use previous
principles :-)

0
Reply Loki 3/11/2006 11:18:10 AM


1 Replies
291 Views

(page loaded in 0.016 seconds)

Similiar Articles:













7/21/2012 1:20:31 AM


Reply: