Whether we can search multiple strings using or in grep -F


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Whether we can search multiple strings using or in grep -F
# 1  
Old 04-22-2013
Whether we can search multiple strings using or in grep -F

Hi,

Whether we can search multiple strings using or in grep -F

In Generally,

Code:
 grep -F "string1" "filename.txt"

How to search for multiple string using grep -F as we using grep

Code:
 grep "string1\|string2" "filename.txt"


Regards,
Nanthagopal A
# 2  
Old 04-22-2013
AND or OR logic?
Does it have to include both strings or either string?
# 3  
Old 04-22-2013
Quote:
Originally Posted by joeyg
AND or OR logic?
Does it have to include both strings or either string?
I need to search for both the string.

Last edited by nanthagopal; 04-22-2013 at 10:58 AM..
# 4  
Old 04-22-2013
Code:
man grep
man fgrep

I think a newline separator works with all fgrep
Code:
grep -F "\
string1
string2"
"filename.txt"

This is string1 OR string2
# 5  
Old 04-22-2013
Quote:
I need to search for both the string.
It would help greatly to give example test input, and expected output.
# 6  
Old 04-22-2013
If you want lines containing both string1 and string2, try:
Code:
grep -F 'string1' filename.txt|grep -F 'string2'

If you want lines containing string1, string2, or both; try:
Code:
grep -F 'string1
string2' filename.txt

# 7  
Old 04-22-2013
Quote:
If you want ..., try
Quote:
If you want ..., try
That's why I asked for test input. The problem statement is too vague. Smilie
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Search between two strings for multiple occurances

i search between two strings viz <app-deployment> & </app-deployment> and save the contents in a new file using the code snippet below. sed -n "/<app-deployment/,/<\/app-deployment>/p" deploy.tmp >found1.tmpBut if the search string apprears more than once in the file then how can i store the... (3 Replies)
Discussion started by: mohtashims
3 Replies

2. Shell Programming and Scripting

Grep multiple strings in multiple files

Hi, every one! I have a file with multiple strings. file1 ATQRGNE ASQGVKFTE ASSQYRDRGGLET SPEQGARSDE ASSRDFTDT ASSYSGGYE ASSYTRLWNTGE ASQGHNTD PSLGGGNQPQH SLDRDSYNEQF I want to grep each string in hundreds of files in the same directory, further, I want to find out the string... (7 Replies)
Discussion started by: xshang
7 Replies

3. Shell Programming and Scripting

Search & Replace: Multiple Strings / Multiple Files

I have a list of files all over a file system e.g. /home/1/foo/bar.x /www/sites/moose/foo.txtI'm looking for strings in these files and want to replace each occurrence with a replacement string, e.g. if I find: '#@!^\&@ in any of the files I want to replace it with: 655#@11, etc. There... (2 Replies)
Discussion started by: spacegoose
2 Replies

4. UNIX for Dummies Questions & Answers

Grep multiple strings in multiple files using single command

Hi, I will use below command for grep single string ("osuser" is search string) ex: find . -type f | xarg grep -il osuser but i have one more string "v$session" here i want to grep in which file these two strings are present. any help is appreciated, Thanks in advance. Gagan (2 Replies)
Discussion started by: gagan4599
2 Replies

5. UNIX for Dummies Questions & Answers

grep command to find multiple strings in multiple lines in a file.

I want to search files (basically .cc files) in /xx folder and subfolders. Those files (*.cc files) must contain #include "header.h" AND x() function. I am writing it another way to make it clear, I wanna list of *.cc files that have 'header.h' & 'x()'. They must have two strings, header.h... (2 Replies)
Discussion started by: ritikaSharma
2 Replies

6. Shell Programming and Scripting

Search multiple Strings in a File

Hi I want to search multiple strings in a file . But the search should start with "From" Keyword and end with before "Where" keyword. Please suggest me. Thanks (2 Replies)
Discussion started by: sboss
2 Replies

7. UNIX for Dummies Questions & Answers

Search for multiple strings and mail accordingly

Hi, I need to find if there is any error in the last few lines of the log file and send a mail accordingly.For example, Following errors can be logged in the log file. ERR_1="DB Connection not established" ERR_2="Server Unloading" I need to find if these errors are found in the log file and... (3 Replies)
Discussion started by: AnneAnne
3 Replies

8. Shell Programming and Scripting

How to search multiple strings in a file

Hi All, I want to search all the ksh scripts that has following details. 1. Search for "exit 0" 2. Search for "sqlldr" or sqlplus" 3. In the above files i want to search for all the script that has no "case" in it. Please advice. Thanks, Deep (2 Replies)
Discussion started by: deepakpv
2 Replies

9. Shell Programming and Scripting

grep: outputting search strings

Newbie question -- any help very much appreciated: I want to be able to get grep (or whatever else would work) to return not only matching lines, but also the original input string: An example may help: Suppose I have two files data1.txt and data2.txt: data1.txt Hello my name is foo. What... (3 Replies)
Discussion started by: tapmas
3 Replies

10. Shell Programming and Scripting

Problem to search multiple strings

Hi all, I am search a string from a file using following command, I want to pick the message ( I.e print $5) from the lookup file if and only if both $hostname and $instancename match. Message=`cat $lookup_tbl| awk '/'$category'/ {if ('$hostname' == '$2' || '$instancename' == '$3') print $5}'`... (2 Replies)
Discussion started by: sudhish
2 Replies
Login or Register to Ask a Question