Using egrep to output expressions which are not found


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Using egrep to output expressions which are not found
# 8  
Old 02-15-2013
You probably do have grep -q somewhere on your system, on Solaris use /usr/xpg4/bin/grep
Otherwise you could use:

Code:
if grep "Schema Area" >/dev/null file &&
   grep stock         >/dev/null file &&
   grep route_drop    >/dev/null file && 
   grep test123       >/dev/null file
then   
  echo correct
else
  echo incorrect
fi

or

Code:
if { grep "Schema Area" file &&
     grep stock         file &&
     grep route_drop    file &&
     grep test123       file
   } > /dev/null
then
  echo correct
else
  echo incorrect
fi


Last edited by Scrutinizer; 02-15-2013 at 06:55 AM..
This User Gave Thanks to Scrutinizer For This Post:
# 9  
Old 02-15-2013
fantastic thank you Scrutinizer that option works perfectly Smilie

not sure why it wont let me use the grep -q option youve posted I get this when I try

Code:
grep: illegal option -- q
Usage: grep -hblcnsviw pattern file

Code:
/usr/xpg4/bin/grep

does exist though
# 10  
Old 02-15-2013
Good, yes, then you could use /usr/xpg4/bin/grep -q instead of grep -q. That standard grep on Solaris is only present for legacy reasons..
This User Gave Thanks to Scrutinizer For This Post:
# 11  
Old 02-15-2013
That works now too Smilie both produce the same results so is one prefered to the other or doesnt it matter?
# 12  
Old 02-15-2013
It's up to you Smilie
# 13  
Old 02-15-2013
Code:
awk '/^size/ && ! NF==6 { print "Something missing" } filename

---------- Post updated at 05:01 PM ---------- Previous update was at 04:56 PM ----------

please ignor my previous post.

Code:
 awk '$1 ~ /^Size/ && NF != 7 { print "Something missing"}' filename

# 14  
Old 02-15-2013
Things like -q are command specific, but if you want a silent test, just run the command into a variable:
Code:
cmd_oput=$( some_command args ... 2>&1 )

---------- Post updated at 10:51 AM ---------- Previous update was at 10:38 AM ----------

You can do file evaluation in one pass in shell, too, using file globbing metachar:
Code:
ct1=0 ct2=0 ct3=0 ct4=0
 
while read l
 do
  case "$l" in
   (*"Schema Area"*)
    (( ct1++ ))
    ;;
   esac
  case "$l" in
   (*stock*) 
    (( ct2++ ))
    ;;
   esac
  case "$l" in
   (*route_drop*) 
    (( ct3++ ))
    ;;
   esac
  case "$l" in
   (*test123*) 
    (( ct4++ ))
    ;;
   esac
 done < in_file
# process counts $ct1-4 to determine response

Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Going mad on an egrep command (Reg Expressions)

Dear community, I am trying for several hours now to create an egrep command to grep the number of lines containing a specific text from a text-file but seem to have an error somewhere. The Textfile contains several thousand lines and has the expression "Lastname" in several lines.... (3 Replies)
Discussion started by: Donzo
3 Replies

2. UNIX for Dummies Questions & Answers

Egrep output

If I have an output from egrep that has two elements on separate lines can I concatenate them? so the egrep for examople might be: egrep "filename|type" And the actual output might be: ./file001.doc Type Text Document How do I get the egrep to remove the line feed so the output is: ... (5 Replies)
Discussion started by: TuftyDave
5 Replies

3. Shell Programming and Scripting

egrep output order

The order of egrep output seems to be as they occur in the file. How do I get the order as requested? For e.g. file contents: AAA EEE GGG egrep 'GGG|AAA|EEE' file gives AAA EEE GGG instead of GGG AAA EEE (2 Replies)
Discussion started by: madhavb
2 Replies

4. Shell Programming and Scripting

bash: need to have egrep to return a text string if the search pattern has NOT been found

Hello all, after spending hours of searching the web I decided to create an account here. This is my first post and I hope one of the experts can help. I need to resolve a grep / sed / xargs / awk problem. My input file is just like this: ----------------------------------... (6 Replies)
Discussion started by: bash4ever
6 Replies

5. Homework & Coursework Questions

Regular expressions output is whole line

Hi, I am newbie in shell programming and I need some help. I had some data and I format it in a file like dn: uid=aaaaa, dc=exmple, dc=com cn: bbbb cccc sn: cccc telephoneNumber:+30-6543-123456 I have to extract the information aaaaa , bbbb, cccc and the phone number using awk... (3 Replies)
Discussion started by: pro
3 Replies

6. Shell Programming and Scripting

Output section of file between two expressions multiple times

Attached is the exact ouput of a vmware VDR log file I am working with but what I am trying to achieve is as follows: I need to output sections of the file using the string "Normal backup" as the start and "Duration" as the end to seperate files so I can then manipulate them further to create... (2 Replies)
Discussion started by: jelloir
2 Replies

7. Shell Programming and Scripting

egrep output each file in new line

I have the following script that searches in several files and shows the search results and the matches filename on the screen. find . -exec egrep -wH "word1|word2" {} \; the output from the search display as: file1 word1 word2 I need to show each file search output result on new... (5 Replies)
Discussion started by: konddor
5 Replies

8. Shell Programming and Scripting

How to grep/awk/egrep two values for given output?

Dear Friends, I have a command which can result following output. Packet is: /var/adm/yyyy/pkt6043 Intended for network : /vob/repo I would like to retrive pkt6043 and /vob/repo using single command. Blue color test will be always contstant and red color text will be dynamic ... (2 Replies)
Discussion started by: baluchen
2 Replies

9. Shell Programming and Scripting

test egrep not found

Hi, I want to return failure from my script if a string is NOT found in a file, but I can't work out how to negate my "if". At the moment I have : if (egrep -i 'search string' filetosearch); then echo "found" else return 2 fi How can I get rid of the echo bit and just test for "string... (4 Replies)
Discussion started by: cdines
4 Replies

10. Shell Programming and Scripting

Comma Delimited Output w/ egrep

Hi all, I have an input file that I am pulling out certain phases using the following commands: cat /nodes.txt | egrep -e 'OSVersion|PrimaryNodeName' Currently the output looks like this: OSVersion - 5.0 PrimaryNodeName - serverA OSVersion - 5.0 PrimaryNodeName - serverB OSVersion... (2 Replies)
Discussion started by: indianadoug
2 Replies
Login or Register to Ask a Question