Searching for multiple words on a line in any order issue


 
Thread Tools Search this Thread
Top Forums UNIX for Dummies Questions & Answers Searching for multiple words on a line in any order issue
# 1  
Old 04-17-2011
Searching for multiple words on a line in any order issue

Hi again

I have figured out how to be able to sort through lines in a file with multiple words in any order and display them using this command:

Code:
cat file | grep -i $OPTION1 | grep -i $OPTION2 | grep -i $OPTION3

OPTION1 is 2008, OPTION2 is Mar, OPTION 3 is Tue

Result:

Code:
Tue Mar 25 23:35:00 GMT 2008
Tue Mar 25 21:34:23 GMT 2008
Tue Mar 25 18:18:10 GMT 2008
Tue Mar 25 15:54:13 GMT 2008
Tue Mar 25 13:21:40 GMT 2008

But, my issue is if I want to display 2 days of the week, nothing appears because the grep has already removed the lines with aren't the first day to begin with (I presume).

Is there any way around this?

Thanks. Smilie
# 2  
Old 04-17-2011
Code:
grep -E "day1|day2"

# 3  
Old 04-28-2011
Hi

Sorry for the late reply, I have been busy.

You help sort of works. But the issue now is that I can view multiple days, but if I want to match say, Tue with Mar and 2008, it shows all Tue results, all Mar results, and all 2008 results, which is not what I need:

Code:
1.13.233.120       Sat Mar 01 14:10:29 GMT 2008
1.10.223.120       Tue Sep 27 12:30:55 GMT 2007
1.10.223.120       Tue Sep 24 13:09:10 GMT 2007
1.10.223.120       Tue May 19 01:17:30 GMT 2008
1.10.223.120       Tue May 16 08:15:31 GMT 2008

Code:
cat file | grep -E "$OPTION1|$OPTION2|OPTION3"

I want it so it should display Tue with Mar and 2008 on the same line (as in the first post) but be able to search for multiple days, months or years also. So Mon, Tue, Mar, 2008 would show Mondays and Tuesdays in March and 2008.

Sorry I should have made this clearer at the beginning.

Last edited by semaj; 04-28-2011 at 06:06 AM..
# 4  
Old 05-03-2011
No one?
# 5  
Old 05-04-2011
I guess this is what you wanted:
Code:
grep 'Tue Mar.* 2008'

 
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Search words in multiple file line by line

Hi All I have to search servers name say like 1000+ "unique names" line by line in child.txt files in another file that is a master file where all server present say "master.txt",if child.txt's server name matches with master files then it print yes else no with server name. (4 Replies)
Discussion started by: netdbaind
4 Replies

2. Shell Programming and Scripting

USING sed to remove multiple strings/words from a line

Hi I use sed comnand to remove occurance of one workd from a line. However I need to removed occurance of dufferent words in ne line. Original-1 Hi this is the END of my begining Comand sed s/"END"/"start"/g Output-1 Hi this is the start of my beginig But I have more... (9 Replies)
Discussion started by: mnassiri
9 Replies

3. Shell Programming and Scripting

sed - searching token in certain order

Hello. I would like to write a bash function which would return "true" if the search succeed else return anything else. something like if ] ; then exit 1 fi function my_funct () { find first occurrence $2 in $1 if not found return "false" from that position,... (6 Replies)
Discussion started by: jcdole
6 Replies

4. Shell Programming and Scripting

Multiple Interval cron issue with order of execution

55,0 5,6 * * * myScript This cron task will execute on 5:00AM, 5:55AM, 6:00AM and 6:55AM. Is there any possibility to make it run only in the order specified such as 5:55AM and 6:00AM (basically only on the 2 intervals) ? (1 Reply)
Discussion started by: vikram3.r
1 Replies

5. Shell Programming and Scripting

Perl, searching multiple files and printing returned line to new file

I am trying to find a way to utilise the full potential of my cpu cores and memory on my windows machine. Now, I am quite familiar with grep, however, running a Unix based OS is not an option right now. Unfortunately, the 32 bit grep for windows that I am running, I cannot run multiple... (1 Reply)
Discussion started by: Moloch
1 Replies

6. Shell Programming and Scripting

awk script to get words which are not in a particula order

Hi all, I need a big help. I've a requirment which should be done in awk scripting only.. My requirment is: In below file, there are some lines started with 'master replica:'. i want to get the exact word in that line which should be before '@', and i've to create a file with these names... (5 Replies)
Discussion started by: raghu.iv85
5 Replies

7. Shell Programming and Scripting

Keep lines with specific words up in an order

I hava a file with following data: number|CREDIT_ID|NULL date|SYS_CREATION_DATE|NULL varchar2|GGS_COMMIT_CHAR|NULL varchar2|GGS_OP_TYPE|NULL number|GGS_SCN|NULL| number|GGS_LOG_SEQ|NULL number|GGS_LOG_POS|NULL number|GGS_ORACREC_SCN|NULL varchar2|BATCH_ID|NULL char|GGS_IMAGE_TYPE|NULL ... (6 Replies)
Discussion started by: kolesunil
6 Replies

8. Shell Programming and Scripting

grep multiple words in a single line

Hi.. How to search for multiple words in a single line using grep?. Eg: Jack and Jill went up the hill Jack and Jill were best friends Humpty and Dumpty were good friends too ---------- I want to extract the 2nd statement(assuming there are several statements with... (11 Replies)
Discussion started by: anduzzi
11 Replies

9. UNIX for Dummies Questions & Answers

Perl searching and printing multiple target in the same line

Hello, I'm trying to create a program in perl called myfind.pl; To use the program: (at the command line)$ program.pl keyword filename note: the keyword is any word or regular expression and it should display the result just like when you 'cat' the file name but with the keyword in... (2 Replies)
Discussion started by: Horizon666
2 Replies

10. Shell Programming and Scripting

compare strings, words in different order

Hi, Would anyone know how to compare two strings, and only throw an error if there were different words, not that the same words were in a different order? e.g "A B C" vs "B C A" ->OK "A B C" vs "A D C" -> BAD Thanks! (2 Replies)
Discussion started by: rebelbuttmunch
2 Replies
Login or Register to Ask a Question