Looking to get a head start on your next software interview? Pickup a copy of the best book to prepare: Cracking The Coding Interview!
To use `sed` to get the primitive value of a string, we can use the following command:
echo "string" | sed 's/.*\///'
In this command, we are piping the string “string” to `sed`. The `s` command in `sed` is used to substitute one string for another. In this case, we are substituting everything up to and including the last forward slash with nothing. This effectively removes everything except the primitive value of the string.
Let’s look at an example. If we have the string “/path/to/file.txt”, we can use the following command to get the primitive value “file.txt”:
echo "/path/to/file.txt" | sed 's/.*\///'
This will output “file.txt”.