Say I have a string foobarHow can I easily produce something like [f]oobar without specifically replacing f with [f]?Use case: I accept user input of a process name, and I want to show the process details while eliminating the grep.
Wrap first character of a string using sed
text processing;sed
Do:sed 's/^./[&]/'^. matches the first character of lineIn the replacement, & is expanded to the match, we are enclosing the match with []Example:% sed 's/^./[&]/' <<<'foobar'[f]oobar