I know how to use the utility sed in bash, and grep is also good. But for the output, they always output a line containing the pattern.
Is there a way in bash to cut out a particular string containing the pattern I want (using regexp)?
That's why you have --help flag, grep --help:
-o, --only-matching show only the part of a line matching PATTERN
Now you can
$ echo 'hello world' | grep -o hello
hello
Using sed:
$ echo "hello world" | sed 's/.*\(hello\).*/\1/'
sed to do that? I am just curious, not for a particular goal.\1 affecting the result? I don't see any about this in the sed manual page.\1 is the first group, which is the hello. It's a regex thing.sed 's/.*\(hello\).*/\1/' really means?regexp to group first, right?
grep -ois what you are looking for.