LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Programming (https://www.linuxquestions.org/questions/programming-9/)
-   -   grep multiple file (https://www.linuxquestions.org/questions/programming-9/grep-multiple-file-853231/)

divyashree 12-30-2010 05:45 AM

grep multiple file
 
I want grep multiple files:

let abc.1.abc.2,abc.3,abc.4

I use grep <pattern> abc.* to read the files. But here grep read files in the order of 1,2,3,4 . I want to to grep the files in reverse order like 1st the abc.4 file will be read and abc.1 file will be last.

Is this possible ?

druuna 12-30-2010 05:51 AM

Hi,

grep xyz $(ls -r abc.*)

Hope this helps.

Trumpen 12-30-2010 06:02 AM

If your shell provides "brace expansion" you could use it:

Code:

grep <pattern> abc.{4..1}

divyashree 12-30-2010 06:21 AM

Quote:

Originally Posted by Trumpen (Post 4207614)
If your shell provides "brace expansion" you could use it:

Code:

grep <pattern> abc.{4..1}

This may help,but I dont know the number of files.

zonah12 10-26-2011 01:44 AM

grep multiple words
 
Thankyou so much for the solutions but its not working. I will try to elaborate by giving more examples.
file TOP.txt

Foul
Tall
blot
grail
House
System
Galaxy
jar
trophy
laptop

This file contains 10 words

Second file all.txt


system ns01
broad ns02
house ns03
laptop ns04
trophy ns05
ginger ns06
foul ns07
dustbin ns08
mugs ns09
blot ns10
pack ns11
butter ns12
jar ns13
knife ns14
kangroo ns15
galaxy ns16
kind ns17
heart ns18
grail ns19
short ns20
tall ns21
table ns22
chair ns23
blot ns24
onion ns25
foul ns26

this file contains 26words with their codes, now what i want to do is to relate the top file words with the codes in all.txt files omiting the words which are not present in the top file. that is i want the result to look like this
Result
Foul ns26
Tall ns21
blot ns24
grail ns19
House ns03
System ns01
Galaxy ns16
jar ns13
trophy ns05
laptop ns04

two things important firstly words are not arranged alphabetically and secondly they are not case sensitive that is similar words might be in small alphabet in top file where as in capital in all file.
I hape i have given the clear e.g. now

crts 10-26-2011 04:51 AM

@zonah12: You are already receiving answers in your other thread:
http://www.linuxquestions.org/questi...r-file-909296/

Please do not crosspost and keep the discussion in one place.


All times are GMT -5. The time now is 05:49 AM.