How to extract one line in every 3 lines from a file?

How to extract one line in every 3 lines from a file?

Post by zhengqua » Sun, 04 May 2008 06:40:13


Hello,
I would like to extract a line from every 3 lines from a file.
the files looks like

1.1
1.2
1.3
1.4
1.5
1.6

I only want to extract 1.1 and 1.4 and put them in a different file,
thanks for
your help!

Zhengquan
 
 
 

How to extract one line in every 3 lines from a file?

Post by mallin.she » Sun, 04 May 2008 06:59:25

zhengquan scrisse:



With GNU sed:


sed -n '1~3' infile > outfile

 
 
 

How to extract one line in every 3 lines from a file?

Post by Ed Morto » Sun, 04 May 2008 07:05:58


awk '!((NR-1)%3)' file > newfile

Ed.
 
 
 

How to extract one line in every 3 lines from a file?

Post by Ed Morto » Sun, 04 May 2008 07:08:23


ITYM:

sed -n '1~3p' infile > outfile

Ed.
 
 
 

How to extract one line in every 3 lines from a file?

Post by zhengqua » Sun, 04 May 2008 10:09:50


Thank you guys!

Zhengquan
 
 
 

How to extract one line in every 3 lines from a file?

Post by Dave » Sun, 04 May 2008 18:49:33


You need to print the line:

sed -n '1~3p' infile > outfile

and, you can do the same just as easily with standard sed:

sed -n '1,${p;n;n}' infile > outfile

--
D.