Here are a few alternatives; One is the use of shell expressions, the other is a relative of grep, agrep:
Code:
#!/usr/bin/env ksh
#!/usr/bin/env bash
#!/usr/bin/env zsh
# @(#) s1 Demonstrate match multiple strings AND and OR, agrep, shell.
# Utility functions: print-as-echo, print-line-with-visual-space.
LC_ALL=C ; LANG=C ; export LC_ALL LANG
pe() { for _i;do printf "%s" "$_i";done; printf "\n"; }
pl() { pe;pe "-----" ;pe "$*"; }
em() { pe "$*" >&2 ; }
db() { ( printf " db, ";for _i;do printf "%s" "$_i";done;printf "\n" ) >&2 ; }
db() { : ; }
C=$HOME/bin/context && [ -f $C ] && . $C dixf agrep
FILE=${1-data1}
pl " Data file $FILE:"
cat $FILE
pl " With agrep, \"and\":a b c :"
agrep "a;b;c" $FILE
pl " With agrep, \"or\":a b c :"
agrep "a,b,c" $FILE
# A pattern-list is a list of one or more patterns
# separated from each other with a & or |. A & signifies
# that all patterns must be matched whereas | requires
# that only one pattern be matched.
# shopt -s extglob
# shopt extglob
pl " With shell expressions, \"and\", a b c ksh (bash, zsh fail):"
while read line
do
if [[ $line == @(*a*&*b*&*c*) ]]
then
pe "Matched line: $line"
fi
done < $FILE
pl " With shell expressions, \"or\", a b c ksh (zsh fail):"
while read line
do
if [[ $line == @(*a*|*b*|*c*) ]]
then
pe "Matched line: $line"
fi
done < $FILE
pl " Some detail about agrep:"
dixf agrep
exit $?
producing:
Code:
$ ./s1
Environment: LC_ALL = C, LANG = C
(Versions displayed with local utility "version")
OS, ker|rel, machine: Linux, 3.16.0-4-amd64, x86_64
Distribution : Debian 8.7 (jessie)
ksh 93u+
dixf (local) 1.42
agrep - ( /usr/bin/agrep, 2012-04-12 )
-----
Data file data1:
also
abracadabra
chock full of beans
hello, world.
silent
-----
With agrep, "and":a b c :
abracadabra
chock full of beans
-----
With agrep, "or":a b c :
also
abracadabra
chock full of beans
-----
With shell expressions, "and", a b c ksh (bash, zsh fail):
Matched line: abracadabra
Matched line: chock full of beans
-----
With shell expressions, "or", a b c ksh (zsh fail):
Matched line: also
Matched line: abracadabra
Matched line: chock full of beans
-----
Some detail about agrep:
agrep search a file for a string or regular expression, with... (man)
Path : /usr/bin/agrep
Version : - ( /usr/bin/agrep, 2012-04-12 )
Type : ELF 64-bit LSB shared object, x86-64, version 1 (S ...)
Help : probably available with -h
Repo : Debian 8.7 (jessie)
The agrep will be much faster for files of more than trivial size.
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)
hey guys,
Hey all,
I'm doing a project currently and want to index words in a webpage.
So there would be a file with webpage content and a file with list of words, I want an output file with true and false that would show which word exists in the webpage.
example:
Webpage content... (2 Replies)
Hi to all
Sorry for the confusion because I did not explain the task clearly.
There are many .hhr files in a folder
There are so many lines in these .hhr files but I want only the following 2 lines to be transferred to the output file.
The keyword No 1 and all the words in the next line
They... (5 Replies)
Hi
I am trying to determine number of lines having a specific keyword.
So for that I am using below query:
grep -i 'keyword1' filename|wc -l
This give me number of lines. Perfect for me.
However now the requirement is
I have multiple keywords together... and I have to find number of... (3 Replies)
Hi,
I have a file containing list of strings like
i:
Pink
Yellow
Green
and I have file having list of file names in a directory
j :
a
b
c
d
Where j contains of a ,b,c,d are as follows
a:
Pink (3 Replies)
Hi,
I want to grep multiple patterns from multiple files and save to multiple outputs. As of now its outputting all to the same file when I use this command.
Input : 108 files to check for 390 patterns to check for. output I need to 108 files with the searched patterns.
Xargs -I {} grep... (3 Replies)
I have below text file only with one line:
vi test.txt
This is the first test from a1.loa1 a1v1, b2.lob2, "c3.loc3" c3b1, loc4 but not from mot3 and second test from a5.loa5
Below should be the output that i want:
a1.loa1
b2.lob2
c3.loc3
loc4
a5.loa5
alv1 and c3b1 should be... (3 Replies)
The Problem that I am having is when the code ran and populated the progflag.csv file, columns MEMSIZE, SECOND and SASEXE were blank. The next problems are the IF else statement isn't working and the email function isn't sending the progflag.csv attachment.
a. What I want the program to do is to... (2 Replies)
I have several problems with my program: I hope you can help me.
1) the If else statement isn't working . The IF Else syntax is:
If MEMSIZE OR sasfoundation (SASEXE) OR Real Time(second) >1.0 and Filename, output column name and value to csv or else nothing
Example progflag,cvs:... (13 Replies)
Discussion started by: dellanicholson
13 Replies
LEARN ABOUT SUNOS
shells
shells(4) File Formats shells(4)NAME
shells - shell database
SYNOPSIS
/etc/shells
DESCRIPTION
The shells file contains a list of the shells on the system. Applications use this file to determine whether a shell is valid. See getuser-
shell(3C). For each shell a single line should be present, consisting of the shell's path, relative to root.
A hash mark (#) indicates the beginning of a comment; subsequent characters up to the end of the line are not interpreted by the routines
which search the file. Blank lines are also ignored.
The following default shells are used by utilities: /bin/bash, /bin/csh, /bin/jsh, /bin/ksh, /bin/pfcsh, /bin/pfksh, /bin/pfsh, /bin/sh,
/bin/tcsh, /bin/zsh, /sbin/jsh, /sbin/sh, /usr/bin/bash, /usr/bin/csh, /usr/bin/jsh, /usr/bin/ksh, /usr/bin/pfcsh, /usr/bin/pfksh,
/usr/bin/pfsh, and /usr/bin/sh, /usr/bin/tcsh, /usr/bin/zsh. Note that /etc/shells overrides the default list.
Invalid shells in /etc/shells may cause unexpected behavior (such as being unable to log in by way of ftp(1)).
FILES
/etc/shells lists shells on system
SEE ALSO vipw(1B), ftpd(1M), sendmail(1M), getusershell(3C), aliases(4)SunOS 5.10 4 Jun 2001 shells(4)