Question: i want to extract block of text based on ids present in another file,

Input

```
>Feature scaffold1
1   100 g
101 200 g
201 300 g
500 500 r
900 1000    r
>Feature scaffold2
1   100 g
01  500 g
200 300 r
>Feature scaffold3
10  500 g
100 200 r
>Feature scaffold4
10  300 g
500 600 r
>Feature scaffold5
1   1000    r

```

id.txt

```
scaffold1
scaffold3
scaffold4

```

output.txt

```
 >Feature scaffold1
 1   100 g
 101 200 g
 201 300 g
 500 500 r
 900 1000    r
 >Feature scaffold3
 10 500 g
 100    200 r
 >Feature scaffold4
 10 300 g
 500    600 r

```

so i want block of text for the ids present in id.txt
Is there any way to do this?

Answer: 
Perl solution:

```
#!/usr/bin/perl
open $ids, '<', 'id.txt' or die $!;
chomp, $h{$_} = 1 while <$ids>;

open $in, '<', 'input.txt' or die $!;
while (<$in>) {
    $id = $1 if />Feature (.*)/;
    print if $h{$id};
}

```

It first loads the ids into a hash, then it reads the input file line by line, sets the current id if needed, and checks the hash whether the current id is stored there or not, and prints the line only for the stored ones.
I have done by below method

```
for i in  scaffold1 scaffold3 scaffold4
> do
> sed -n "/$i/,/scaffold/p" inputfile | sed '$d'
> done

```

output. 

```
Feature scaffold1
1   100 g
101 200 g
201 300 g
500 500 r
900 1000    r
>Feature scaffold3
10  500 g
100 200 r
>Feature scaffold4
10  300 g
500 600 r

```