Im using the below command to search a file for multiple expressions if the 4th expression doesnt exist the command simply lists what it can find and ignores what it cant. Is there any way to get the command to output an error or a message if it cant find the 4th expression to a file?
sorry I dont have the use of nawk or grep with the -q switch
egrep -v wouldn't get what Im looking for as it wouldnt highlight any errors
sorry I only have limited knowledge of awk and sed so Im not sure how I would use them in this case
What I am looking for is by using grep or egrep or any other command to search though a file for expression1|expression2|expression3 etc... and if it can't find one of the expressions output an error along the lines of "can't find expression1". If it does find the expression in the file then do nothing and output nothing.
Thankyou for all your help so far people
---------- Post updated at 04:05 AM ---------- Previous update was at 04:01 AM ----------
the input file looks like this and carries on:
Area Name: Schema Area
Size: 77823936, Records/Block: 64, Area Number: 6
Area Name: stock
Size: 1024192, Records/Block: 64, Area Number: 100
Area Name: route_drop
Size: 4096768, Records/Block: 256, Area Number: 101
Things like -q are command specific, but if you want a silent test, just run the command into a variable:
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:
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