how to get every 4th line from a file?

P

papori

Guest
Hi guys,
I have a text file ..
I want to get every 4th line into a new file, but I want the line count will start from the 2th line.
For example for file with 20 lines, i want line numbers:
2
6
10
14
18

Any simple ideas?

Thanks,
Pap
 


OP
H

hackinjack

Guest
Extracting lines from file

Hi guys,
I have a text file ..
I want to get every 4th line into a new file, but I want the line count will start from the 2th line.
For example for file with 20 lines, i want line numbers:
2
6
10
14
18

Any simple ideas?

Thanks,
Pap

Code:
awk '{if (! ((FNR + 2) % 4)) { print }}' myfile > newfile

Explanation: Parse file "myfile" - IF ((current line number in file plus 2) modulo 4) is NOT TRUE print current line and redirect output to file "newfile"

HTH :)
 
OP
P

papori

Guest
Code:
awk '{if (! ((FNR + 2) % 4)) { print }}' myfile > newfile

Explanation: Parse file "myfile" - IF ((current line number in file plus 2) modulo 4) is NOT TRUE print current line and redirect output to file "newfile"

HTH :)

That's help!
 
MALIBAL Linux Laptops

Linux Laptops Custom Built for You
MALIBAL is an innovative computer manufacturer that produces high-performance, custom laptops for Linux.

For more info, visit: https://www.malibal.com

Members online


Top