Visit Our UNIX and Linux User Community


Logical AND operation with egrep


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Logical AND operation with egrep
# 1  
Old 09-01-2009
Logical AND operation with egrep

Hi All,

I need to perform logical AND operation using UNIX command.
string(space separated) is coming through web. And i dont want to create
files for that. i want to use only source file.

Any help would be appreciated.

Regards,
Sam
# 2  
Old 09-01-2009
Tools chained (piped) commands performs AND

file1=
Joe, Linda, Bob, Terry
Kim, Rhonda, Steve, Joy

Code:
cat file1 | grep "Joe" | grep "Linda"

would output that first line of
Joe, Linda, Bob, Terry

Or, are you asking something different? Sometimes easier to understand with examples.
# 3  
Old 09-01-2009
ok here is the example :-

below is the string coming from web application

string="str1 str2 str3"

i want to search a record/records which contain all three string by using source file only. Dont want to create any new file.

important :- string coming through web is space separated.
# 4  
Old 09-01-2009
Tools Are the strings variable?

Or is there something else not immediately clear?

cat file | egrep "str1 str2 str3"

to find all records that have those three entries.
# 5  
Old 09-01-2009
strings are coming through web application in a variable.

cat file|egrep "str1 str2 str3" not working.Smilie
# 6  
Old 09-01-2009
Quote:
Originally Posted by sam25
strings are coming through web application in a variable.

cat file|egrep "str1 str2 str3" not working.Smilie
Code:
cat test | egrep "string1 string2 string3"
string1 string2 string3

cat test
string1 string2 string3

That works, I think you need to provide more information.
# 7  
Old 09-01-2009
sorry i forgot to mention one thing my file is CSV file,
and that command is not working with CSV file.

Previous Thread | Next Thread
Test Your Knowledge in Computers #252
Difficulty: Easy
Network computer devices that originate, route and terminate the data are called server-only devices.
True or False?

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Column operation : cosne and sine operation

I have a txt file with several columns and i want to peform an operation on two columns and output it to a new txt file . file.txt 900.00000 1 1 1 500.00000 500.00000 100000.000 4 4 1.45257346E-07 899.10834 ... (4 Replies)
Discussion started by: shashi792
4 Replies

2. Solaris

Operation and Maintenance

I gurus of Solaris, I need to do a Procedure concerning in the Maintenance of Solaris Server. What are the parameters that I must be see Periodically in a Server. For example the space I (df -h) must be each week.- In this server exist a Database aplication (Oracle), and log's that increase or... (4 Replies)
Discussion started by: andresguillen
4 Replies

3. Shell Programming and Scripting

String Operation

/home8/mc09ats/UnixCw/file4 this is the path...i have 2 variables filename and filepath...i want filename=file4 filepath=/home8/mc09ats/UnixCw i.e. i think i have to find last occurence of "/" in string and the string after "/" want to take in some variable and string before last "/"... (4 Replies)
Discussion started by: AbhijitIT
4 Replies

4. Shell Programming and Scripting

File Operation

I have one text file like 1 filename 2 filename2 3 hi 4 myname i have one variable in which i have index value..i.e.1,2,3 and so... i want to copy value after the index into somevariable..... how i can do it.... (2 Replies)
Discussion started by: AbhijitIT
2 Replies

5. UNIX for Dummies Questions & Answers

string operation

I am trying to ask for full name in a script, Then echo back to the user with the surname only, omitting the first name. Thanks (2 Replies)
Discussion started by: orjnet
2 Replies

6. UNIX for Dummies Questions & Answers

search ")" with egrep - egrep: syntax error

Hi Guys, we have a shell script which basically query the Database which retrieves huge data and use the data with "egrep" . Now there is some data which contains characters like "abc)" and the same is used like below : "egrep (.+\|GDPRAB16\|GDPR/11702 96 abc)\|$ temp.txt" now while... (7 Replies)
Discussion started by: sagarjani
7 Replies

7. Shell Programming and Scripting

How to do logical AND and logical OR with grep

Hi can someone please help me on this. I need to perform this code: Grep any lines that meets the following criteria (A AND B) OR (A AND C) I tried this code, but it didn't work Grep-I "A &&B" | "A&&C" *.* $ thanks in advance (12 Replies)
Discussion started by: Needhelp2
12 Replies

8. UNIX for Dummies Questions & Answers

cat operation

Hi, Can anyone explain me what is the functionality of this code cat << EOF > $TSTFILE /$1/ { print "SENT" } EOF Suggestions welcome Thanks in advance (0 Replies)
Discussion started by: trichyselva
0 Replies

9. Shell Programming and Scripting

Array operation

Hi, I would like ask for you help for coding array operation. array= ( a b c d e f ) I would like to remove entry "d" from my array and import the remaining entries back to the array. Thanks. (3 Replies)
Discussion started by: phamp008
3 Replies

10. UNIX for Dummies Questions & Answers

Egrep cheat sheet anywhere? Looking for meaning of egrep -c

Hi I've been searching google and have not found what egrep -c means. Does anyone know where I can get a cheat sheet or what that -c means? thanks, Linda (2 Replies)
Discussion started by: leelm
2 Replies

Featured Tech Videos