I'm running a script that get an argument $1
I want to find all strings that start with either space or .
before that argument.
and end with either .
or %
ex:
if $1
is Table1 then
1) "Table1"
2) " Table1"
3) ".Table1"
4) "Table1."
5) ".Table1."
6) " Table1."
7) ".Table1%"
8) " Table1%"
should be good
If by "finding all strings" you mean "whole lines", it is quite simple:
If you mean matching strings occurring everywhere in a line, then it gets more complex since you have included the plain word "Table1" in your desired matches (match (1.) in your description). I would go with a 2-step approach.
First get all lines containing "Table1" as a word (
grep -w
).Then filter out (
grep -v
) everything you don't want to be matched:or more compact:
result:
grep -v "[^ .]\+$1"
: means Filter-out (-v
) previous-matches which start with a least one character other than "space" or "."If you want to match any "whitespace" (e.g. tabs) and not only the common literal "space", replace the literal space " " in the grep patterns above with
[:space:]