Sponsored Content
Top Forums UNIX for Dummies Questions & Answers Searching for multiple words on a line in any order issue Post 302514657 by semaj on Sunday 17th of April 2011 08:01:34 AM
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
 

10 More Discussions You Might Find Interesting

1. 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

2. 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

3. 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

4. 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

5. 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

6. 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

7. 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

8. 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

9. 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

10. 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
LOOK(1) 							   User Commands							   LOOK(1)

NAME
look - display lines beginning with a given string SYNOPSIS
look [options] string [file] DESCRIPTION
The look utility displays any lines in file which contain string. As look performs a binary search, the lines in file must be sorted (where sort(1) got the same options -d and/or -f that look is invoked with). If file is not specified, the file /usr/share/dict/words is used, only alphanumeric characters are compared and the case of alphabetic characters is ignored. OPTIONS
-a, --alternative Use the alternative dictionary file. -d, --alphanum Use normal dictionary character set and order, i.e. only alphanumeric characters are compared. (This is on by default if no file is specified.) -f, --ignore-case Ignore the case of alphabetic characters. (This is on by default if no file is specified.) -t, --terminate character Specify a string termination character, i.e. only the characters in string up to and including the first occurrence of character are compared. -h, --help Display help text and exit. -V, --version Output version information and exit. The look utility exits 0 if one or more lines were found and displayed, 1 if no lines were found, and >1 if an error occurred. EXAMPLE
sort -d /etc/passwd -o /tmp/look.dict look -t: root:foobar /tmp/look.dict FILES
/usr/share/dict/words the dictionary /usr/share/dict/web2 the alternative dictionary SEE ALSO
grep(1), sort(1) COMPATIBILITY
The original manual page stated that tabs and blank characters participated in comparisons when the alphanum option was specified. This was incorrect, and the current man page matches the historic implementation. HISTORY
The look utility appeared in Version 7 AT&T Unix. AVAILABILITY
The look command is part of the util-linux package and is available from ftp://ftp.kernel.org/pub/linux/utils/util-linux/. util-linux June 2011 LOOK(1)
All times are GMT -4. The time now is 10:58 AM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy