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.

lets say i have few files which have structure like

file1.txt

apple fruit 
tomato vegetable 

file2.txt

apple red green
tomato green yellow

is there a way to grep at once these 2 files (or more) to receive set of data like this one (or similar)

apple fruit red green
tomato vegetable green yellow
share|improve this question

2 Answers 2

Use join:

$ join file1.txt file2.txt
apple fruit  red green
tomato vegetable  green yellow
share|improve this answer

Just use grep with the pattern and searched files.
Example:

pi@raspberrypi ~ $ echo "test" > a
pi@raspberrypi ~ $ echo "test" > b
pi@raspberrypi ~ $ echo "test" > c
pi@raspberrypi ~ $ grep "test" a b c 
a:test
b:test
c:test

See the adapted man page: http://www.explainshell.com/explain?cmd=grep+%22pattern%22+a+b+c

See also the full man page: http://www.gnu.org/software/grep/manual/grep.html

share|improve this answer
    
Your answer would be improved if you would address the multiple file situation in the OP. –  Elder Geek Sep 2 at 15:19
    
You're right I think I misread his question. I'm confused now, whether I should remove my answer or not. –  Benoit Duffez Sep 2 at 15:44
    
If I were you I'd try to improve it. It might be of interest to view the output of info coreutils 'tee invocation' –  Elder Geek Sep 3 at 21:40

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.