So I'm using a MacOS commandline and have two files
File A.txt
A
B
F
File B.txt
>A
abcde
>B
efghi
>C
jklmn
>D
opqrs
>E
tuvwx
>F
yz123
I want it to go through a while loop through file A.txt and only print the corresponding header and content from file B.txt
>A
abcde
>B
efghi
>F
yz123
This line works when I go through each line in File A individually.
grep -n "\A\,\>\{x;p;}" B.txt
But when I do this:
While read i; do grep -n "\$i\,\>\{x;p;}" B.txt >> newfile.txt; done < A.txt
I get this error:
grep: invalid repetition count(s)
What am I doing wrong?