Issue
/home/user/views/links/user1/gitsrc/database/src/
This is my string. I want to cut it in 2 strings such as "/home/user/views/links/user1/" "/database/src/"
so the delim is not actally a single character but a group of characters ie "gitsrc".
Solution
You can only define a single character as delimiter in cut
.
You could use awk
where the field separator can be a single character, a null string or a regular expression, e.g.
$ echo '/home/user/views/links/user1/gitsrc/database/src/' |
awk -F'gitsrc' '{ print $1 " " $2 }'
/home/user/views/links/user1/ /database/src/
or
$ echo '/home/user/views/links/user1/gitsrc/database/src/' |
awk -F'gitsrc' '{ print $1 ORS $2 }'
/home/user/views/links/user1/
/database/src/
In your shell you could or use a parameter expansion to get the first and second part:
$ str=/home/user/views/links/user1/gitsrc/database/src/
$ echo "${str%%gitsrc*}" # remove longest suffix `gitsrc*`
/home/user/views/links/user1/
$ echo "${str#*gitsrc}" # remove shortest prefix `*gitsrc`
/database/src/
Answered By - Freddy Answer Checked By - Candace Johnson (WPSolving Volunteer)