-1

i have a file with names which i make with three files. i want grep 0 if the pattern is absent from any file and 1 if the pattern is present i am using this command

cat X.nam |xargs -i grep -c -P '{}$' A.nam > a

i am getting this error

grep nothing to repeat

X.nam
A
AADLGS
AAEGVG
AAGVGTWP
AASLSSIT
AASLSSVN
AASLTGCN
ACL*AML
ACLSGSA
ACL*VVM
A.nam
AAGVGTWP
AASLSSIT
AASLSSVN
AASLTGCN
ACL*AML
ACLSGSA

closed as unclear what you're asking by jasonwryan, Jeff Schaller, phk, Anthon, DarkHeart May 19 '17 at 2:27

Please clarify your specific problem or add additional details to highlight exactly what you need. As it's currently written, it’s hard to tell exactly what you're asking. See the How to Ask page for help clarifying this question. If this question can be reworded to fit the rules in the help center, please edit the question.

  • I don't think that's a problem with your grep syntax per se; it's just grep (when in PCRE mode) telling you that one of your patterns contains a quantifier without a preceding regex atom (as you can demonstrate using grep -P '*foo' somefile for example) – steeldriver May 18 '17 at 20:37
  • Is there a line in X.nam that begins with * or +? That would cause this error. – Barmar May 18 '17 at 20:44
  • Do you understand that the lines you're substituting from X.nam will be treated as regular expressions, not matched literally? So ACL*AML will match ACAML, ACLLAML, ACLLLLLLLML`, etc.? – Barmar May 18 '17 at 20:46
  • no i want them to match literally – star May 18 '17 at 21:53
1

That error means you have a quantifier like * or + with nothing before it.

I suspect you don't want the words in X.nam to be treated as regular expressions, they should be matched literally. In PCRE, you can enclose parts of the pattern in \Q and \E to quote them.

cat X.nam |xargs -i grep -c -P '\Q{}\E$' A.nam > a
  • what does \Q and |E stands for – star May 18 '17 at 21:54
  • They stand for quote and end – Barmar May 18 '17 at 21:55
  • ohk thank you. i am trying this hope it will work – star May 18 '17 at 21:56
  • thank you so much Barmur. it works. I am really obliged. i just added x with c cat X.nam |xargs -i grep -cx -P '\Q{}\E$' A.nam > a is it ok – star May 18 '17 at 22:00

Not the answer you're looking for? Browse other questions tagged or ask your own question.