I have to write a shell script to get value from a string, something like:
How can I use
grep command with the use of regular expression to get "pathName"?
Unix & Linux Stack Exchange is a question and answer site for users of Linux, FreeBSD and other Un*x-like operating systems. It only takes a minute to sign up.Sign up to join this community
GNU grep has the
echo 'string="abcdef" pathName' |grep --only-matching "pathName"
will output "pathName".
Update with more info on the required pattern:
echo 'string="abcdef" pathName' |grep --only-matching "[[:graph:]]*$"
[[:graph:]] is the character class of all non-space characters,
* means zero-or-more of the preceding pattern,
$ means end-of-line.
So the pattern matches the longest sequence of non-space characters at the end of the line.