I want to get a string between two special characters. For example,
I want oracle/ggs in the above string.
How can I do this using bash?
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
$ expr /home/oracle/ggs/text.ext : '/home/\(.*\)/' oracle/ggs
That returns the part after
/home/ and before the last
Other possible approaches that will fulfil your requirements:
$ echo /home/oracle/ggs/text.ext | cut -d/ -f3,4 oracle/ggs $ echo /home/oracle/ggs/text.ext | cut -c 7-16 oracle/ggs $ echo oracle/ggs oracle/ggs