ace_ventura
ace_ventura

Reputation: 468

grep Trim txt file by certain line number

I have a txt file containing, let's say, 1000 lines. I would like to trim it obtaining a file with 100 lines, composed by lines 0, 10, 20, 30, etc of the original file.

Is that possible with grep or something? thanks

Upvotes: 0

Views: 261

Answers (1)

Kent
Kent

Reputation: 195039

it could be easily done by awk/sed one-liner:

awk

awk '!(NR%10)' file

sed

sed -n '0~10p' file

or

sed '0~10!d` file

see below example: (sed one liner will give same output)

print the first 10 lines:

kent$  seq 1000|awk '!(NR%10)'|head -10
10
20
30
40
50
60
70
80
90
100

total lines:

kent$  seq 1000|awk '!(NR%10)'|wc -l   
100

Upvotes: 5

Related Questions