Re: Extract a block of lines from a file
- From: Ed Morton <morton@xxxxxxxxxxxxxx>
- Date: Thu, 16 Aug 2007 23:11:32 -0500
Christian wrote:
"Ed Morton" <morton@xxxxxxxxxxxxxx> a écrit dans le message de news: h_qdnRVpzfeAH1nbnZ2dnUVZ_qzinZ2d@xxxxxxxxxxxxxx
Christian wrote:
Hello,
I have a file named myfic.
root : venus - ~> cat myfic
the first line<LF>
the second line<LF>
the third line<LF>
<LF>
the fourth line<LF>
the fifth line<LF>
the sixth line<LF>
root : venus - ~>
The delimiter is the empty line. Here is what I do to extract the second block :
sed 's/^$/@@@@@@@/' myfic | awk 'BEGIN { RS = "@@@@@@@" }
{
if ( NR == 2 )
{
print $0
}
}'
Is there anything simpler using bash?
awk -v RS= 'NR==2' myfic
Ed.
Thanks, that works.
If your input file can be very large you may want to make the script more efficient, in which case change it to:
awk -v RS= 'NR==2{print;exit}' myfic
Regards,
Ed.
.
- References:
- Extract a block of lines from a file
- From: Christian
- Re: Extract a block of lines from a file
- From: Ed Morton
- Re: Extract a block of lines from a file
- From: Christian
- Extract a block of lines from a file
- Prev by Date: Re: File Sincronization between hosts
- Next by Date: Re: Comparing two text files with non-adjacent lines for unique entries
- Previous by thread: Re: Extract a block of lines from a file
- Next by thread: netrc - enabling mutiple accesses to same machine
- Index(es):
Relevant Pages
|