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)
Remove Character from String Using tr The tr command (short for translate) is used to translate, squeeze, and delete characters from a string. You can also use tr to remove characters from a string. For demonstration purposes, we will use a sample string and then pipe it to the tr command.
How do I match and remove (delete) the words “ssh_args=-p 1222” from config file using sed command under Linux or Unix like operating systems? You can use the the substitute sed command changes all occurrences of the “ssh_args=-p 1222”. The same command can be used to delete the required words.
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
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With