Take the 2-minute tour ×
Ask Ubuntu is a question and answer site for Ubuntu users and developers. It's 100% free, no registration required.

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.

share|improve this question
    
grep ^A will show you lines starting with A –  Hakeem Wahab Nov 15 '13 at 13:12
    
Is my command wrong then? or what output do you except from my command. –  Narwen Nov 15 '13 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 '13 at 13:32
add comment

2 Answers 2

up vote 4 down vote accepted

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.

share|improve this answer
add comment

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

share|improve this answer
    
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 '13 at 13:22
    
yup unfortunately your command was wrong :/ –  Hakeem Wahab Nov 15 '13 at 13:27
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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