How to delete a substring using shell script
shell, substring
Solution
Multiple ways, a selection:
`str=abc.out`
Shell:
echo ${str%.*}
Grep:
echo $str | grep -o '^[^\.]*'
Sed:
echo $str | sed -E 's/(.*?)\..*/\1/'
Awk:
echo $str | awk -F. '{print $1}'
`-F.` means split the string by . and `$1` means the first column.
Cut:
`echo $str | cut -d. -f1`
All output:
abc
Problem
I have strings called: ``` abc.out def.out ``` How do I delete the substring .out In these strings? What command should I use? (Bourne Shell)