Logical AND in shell commands


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Logical AND in shell commands
# 1  
Old 07-08-2009
Lightbulb Logical AND in shell commands

HiSmilie,
I have a file that contains :

+-----------------------------------------------------------------------------+
LABEL: super1_fix
EFIX FILES: 1
ABSTRACT: epkg for touch command
PRE-REQUISITES: no
PACKAGER VERSION: 7
REBOOT REQUIRED: no
BUILD BOOT IMAGE: no
FIX TESTED: no

Install Scripts:
PRE_INSTALL: no
POST_INSTALL: no
PRE_REMOVE: no
POST_REMOVE: no

********
Now I want to grep for REBOOT, BUILD BOOT IMAGE, POST_INSTALL, ABSTRACT in this file.

I know that there is egrep to do logical OR...I want to know if we can grep all
the above fields by logical AND? Is there any way that I can grep alll these
in a single stretch of a command??

Thanks in advance,
Vijaya2006
# 2  
Old 07-08-2009
-e PatternList
Specifies one or more search patterns.
e.g.
Code:
# grep -e "^abc" -e " abc " -e "abc$" filename



---------- Post updated at 19:17 ---------- Previous update was at 19:15 ----------

(true for HP-UX 11.11 and sup ( 11.00 is -w...) and AIX >5 the other OS I havent looked yet...)
# 3  
Old 07-08-2009
Code:
egrep 'REBOOT|BUILD BOOT IMAGE|POST_INSTALL|ABSTRACT' file

# 4  
Old 07-13-2009
Java Multiple line handling for grep in shell script

Hi vbe thanx for the reply.
It did solve a part of my problem . But the other thing is :

I put the following line in my script.
grep -e "LABEL" -e "EFIX FILES" -e "PACKAGER VERSION" -e "LOCATION" \
grep -e "PRE_REMOVE" -e "POST_REMOVE" file_name.

Since the line exceeded more than 1, I used "\" . But the script is not recognising this and is throwing error as below:

grep: 0652-033 Cannot open grep.
grep: 0652-033 Cannot open -e.
grep: 0652-033 Cannot open PRE_REMOVE
......
....

Please, tell me how can I overcome this error when I have more than 1 line in the shell script for grep.

Thanks in Advance,
Vijaya2006
# 5  
Old 07-13-2009
Why do you call the command twice? Try this:

Code:
grep -e "LABEL" -e "EFIX FILES" -e "PACKAGER VERSION" -e "LOCATION" \
-e "PRE_REMOVE" -e "POST_REMOVE" file_name

Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. UNIX for Dummies Questions & Answers

Logical OR in shell script

I have code as follows to perform some validations on C++ and Javascript files: if || || ; then However, when I want to add other extensions as well, say "py" or "sql", then the repeated OR starts to look contrived. I know I can use the -o operator to abbreviate the code a little bit, but... (14 Replies)
Discussion started by: figaro
14 Replies

2. Shell Programming and Scripting

Shell grammar question: logical OR in test

Hi, I am trying to check if two input files exist before the rest of the scripts is run. Following is the code that I have but it gives me syntax error. if then echo "File not found" else echo "File found" fi (3 Replies)
Discussion started by: nua7
3 Replies

3. Shell Programming and Scripting

Any shell or hack that makes the shell command line take vi commands?

basically i'm tired of hitting the left arrow a few dozen times when correcting a mistake or modifying a history command i'd like to use vim style key shortcuts while on the command line so that a 55 moves the cursor 55 places to the left... and i want all the other vi goodies, search of... (3 Replies)
Discussion started by: marqul
3 Replies

4. Shell Programming and Scripting

Logical expression in POSIX compliant Korn Shell

Hi, i want to check if a variable var1 is not a or b or c pseudo code: If NOT (var1 = a or var1 = b or var1 = c) then ... fi I want to use POSIX complaint Korn shell, and for string comparison For the following code, logical.sh #!/usr/bin/ksh var="j" echo "Var : $var" if ! { || ||... (12 Replies)
Discussion started by: ysrini
12 Replies

5. Shell Programming and Scripting

nested logical expression in bash shell

Please tell me how to nest logical expressions in bash. I would like to nest logical expressions for arguments of the "test" command on bash. The following pseudo-code shows my intention. // pseudo code if (exp1 AND (exp2 OR exp3)) { Output true; } else { Output false; } ... (11 Replies)
Discussion started by: LessNux
11 Replies

6. Shell Programming and Scripting

How to implement the logical express --- A(B+C) within single "if" statment in shell script?

On Linux OS, bash environment, I want implement the following code: if && ( || ) A,B,C represents some compare conditions. How to realize it ? Thanks! (1 Reply)
Discussion started by: qcmao
1 Replies

7. Shell Programming and Scripting

Can BASH execute commands on a remote server when the commands are embedded in shell

I want to log into a remote server transfer over a new config and then backup the existing config, replace with the new config. I am not sure if I can do this with BASH scripting. I have set up password less login by adding my public key to authorized_keys file, it works. I am a little... (1 Reply)
Discussion started by: bash_in_my_head
1 Replies

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

9. Shell Programming and Scripting

How to run unix commands in a new shell inside a shell script?

Hi , I am having one situation in which I need to run some simple unix commands after doing "chroot" command in a shell script. Which in turn creates a new shell. So scenario is that - I need to have one shell script which is ran as a part of crontab - in this shell script I need to do a... (2 Replies)
Discussion started by: hkapil
2 Replies

10. Shell Programming and Scripting

KORN Shell - Spawn new shell with commands

I want to be able to run a script on one server, that will spawn another shell which runs some commands on another server.. I have seen some code that may help - but I cant get it working as below: spawn /usr/bin/ksh send "telnet x <port_no>\r" expect "Enter command: " send "LOGIN:x:x;... (2 Replies)
Discussion started by: frustrated1
2 Replies
Login or Register to Ask a Question