Thursday, May 2, 2024
12
rated 0 times [  12] [ 0]  / answers: 1 / hits: 9824  / 3 Years ago, mon, june 7, 2021, 7:18:56

How can I get some block of text by lines?



I have a log file with 6000000 lines and I want get just a block of 607366 to 700000.



I've tried something like:



head -n 607366 | tail -700000 server.log > outputFile.txt

More From » command-line

 Answers
6

You can use sed:



sed -n 607366,700000p server.log > outputFile.txt


If you want to use head and tail, this is the right way:



head -n 700000 server.log | tail -n $(echo 700000-607366+1 | bc) > outputFile.txt


or, shorter:



head -n 700000 server.log | tail -n 92635 > outputFile.txt

[#29069] Tuesday, June 8, 2021, 3 Years  [reply] [flag answer]
Only authorized users can answer the question. Please sign in first, or register a free account.
ithriv

Total Points: 46
Total Questions: 115
Total Answers: 96

Location: Malaysia
Member since Wed, May 11, 2022
2 Years ago
ithriv questions
Tue, Mar 14, 23, 14:31, 1 Year ago
Wed, Oct 5, 22, 02:59, 2 Years ago
Fri, Mar 11, 22, 10:12, 2 Years ago
Thu, May 11, 23, 10:55, 1 Year ago
Sun, Sep 26, 21, 06:47, 3 Years ago
;