1

I have three files testx,testy and testz all in same directory Sikh. All three files contain same data or content. The contents are:

aaabb  Aaaaa  AAAAA 

bbbcc  Bbbbb  BBBBB

ff–ff  Ccccc  CCCCC 

cccdd  Ddddd  DDDDD 

Now I want to display the text containing A in all three files. What I have done so far is:

 grep '^A'*

But it does not display anything. So can anyone help me sort this out.

3
  • grep ^A will show you lines starting with A Nov 15, 2013 at 13:12
  • Is my command wrong then? or what output do you except from my command.
    – Narwen
    Nov 15, 2013 at 13:16
  • 1
    grep --no-filename A test? seems to work fine. Just loose the ^ (which means at the beginning of a line) and optionally add a -h or --no-filename to supporess printing the filenames in front of the pattern). Note that test? will match textx, testy and testz, but that * is also quite valid here.
    – Hennes
    Nov 15, 2013 at 13:32

2 Answers 2

4

It doesn't show anything, because your Text has no ^A in it.

The ^ means "Beginning of line". And you have no line that begins with a Capital A.

You could search with:

grep "A" *

This will find the AAAAA in your first Line.

Or search for example:

grep "^a"

That finds the aaabb line in your text.

Grep is case sensitive.

1

If you're looking to display lines containing "A" in the 3 files, try this command:

cat testx testy testz | grep A

sure, if you are in "Sikh" directory

2
  • I can display it but I have a question in my exam where I have to give this command. But when I try it, it displays nothing. So is the question wrong or have I done something wrong.
    – Narwen
    Nov 15, 2013 at 13:22
  • yup unfortunately your command was wrong :/ Nov 15, 2013 at 13:27

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .