Answer the question
In order to leave comments, you need to log in
How to select the required number of lines from a file?
There is such a file
HTTP/2 301
location: https://www.google.com/
content-type: text/html; charset=UTF-8
cache-control: public, max-age=2592000
server: gws
content-length: 220
x-xss-protection: 0
x-frame-options: SAMEORIGIN
alt-svc: quic=":443"; ma=2592000; v="46,43",h3-Q050=":443"; ma=2592000,h3-Q049=":443"; ma=2592000,h3-Q048=":443"; ma=2592000,h3-Q046=":443"; ma=2592000,h3-Q043=":443"; ma=2592000
HTTP/2 301
location: https://www.google.com/
content-type: text/html; charset=UTF-8
cache-control: public, max-age=2592000
server: gws
content-length: 220
x-xss-protection: 0
x-frame-options: SAMEORIGIN
alt-svc: quic=":443"; ma=2592000; v="46,43",h3-Q050=":443"; ma=2592000,h3-Q049=":443"; ma=2592000,h3-Q048=":443"; ma=2592000,h3-Q046=":443"; ma=2592000,h3-Q043=":443"; ma=2592000
Answer the question
In order to leave comments, you need to log in
tac file | sed -n '1,/^$/{/./p}' | tac
The first tac reads the file backwards, sed cuts out the first block of non-blank lines, the second tac reverses that block to its original state.
Printing the last reply:
Printing all responses starting from the second one (relevant for your example):sed -n ' 0,/^$/!p' input.txt
1. Set the variable FILE_N - the sequence number of the output file
2. Read this source file line by line.
3. Compare what you read with the ^HTTP/2 mask
4. If it matches, increase FILE_N
5. Send the read line to a file whose name is formed from FILE_N
6. End of the loop started in step 2
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question