[R] question

Philippe Glaziou glaziou at pasteur-kh.org
Thu Nov 20 01:44:52 CET 2003


Peter Dalgaard <p.dalgaard at biostat.ku.dk> wrote:
> blueberry:~/> sed -e 's/pattern 1\|pattern 2\|pattern xyz//g' < tst.txt
> 2.22 3.45
> 1.56 2.31
> 
> 4.67 7.91
> 3.34 2.15
> 5.32 3.88
> 
> blueberry:~/> awk '/pattern 1/{copy=1;next};/pattern 2/{copy=0};copy==1' < tst.txt
> 4.67 7.91
> 3.34 2.15
> 5.32 3.88
> blueberry:~/> perl -ne 'if(/pattern 1/){$copy=1;next;} if(/pattern 2/){$copy=0;}print if $copy' < tst.txt
> 4.67 7.91
> 3.34 2.15
> 5.32 3.88




I see and here is my (corrected) sed solution:

cunegonde:~/tmp> cat test
2.22 3.45
1.56 2.31
pattern 1
4.67 7.91
3.34 2.15
5.32 3.88
pattern 2

cunegonde:~/tmp> sed -e '/pattern 1\|pattern 2/D' <test
2.22 3.45
1.56 2.31
4.67 7.91
3.34 2.15
5.32 3.88

-- 
Philippe




More information about the R-help mailing list