This question already has answers here:
In VBScript how do you take a string using mid and split the string at say a ";"
(2 answers)
Closed 4 years ago.
I´m looking for any way to remove substring from string starting in the "-" symbol until the string´s end.
Server Down - Windows Server BAWFM-055
Server Up - Linux Server LSWFM-089
In the first example the output will be "Windows Server BAWFM-055"
In the second example the output will be "Linux Server LSWFM-089"
Trim(Mid(MyString, InStr(MyString, "-") + 1))
Where MyString is a variable holding your strings.
The +1 is needed to Skip the minus sign and start at the next character.
Trim to remove eventual leading or trailing spaces.
Related
This question already has answers here:
Using different delimiters in sed commands and range addresses
(3 answers)
Closed 12 months ago.
I have many repositories with the remote origin set to HTTPS. Now I want to change all origin remotes to SSH.
I am using a command for this in which I want to replace all preceeding url = https://gitlab.mypath/ with git#gitlab.maypath:.
Is there a way to express this with one sed call. Something like:
's#https://gitlab.mypath/#git#gitlab.mypath:#g'
I have to be able to escape the first "#g"
The correct anwers
Switch from s### to s|||
Apart from choosing any character for the delimiter, you can also escape that character: #
The explanation
The character after the s specifies the separator, which must occur three times in your s command.
Thanks
#Cyrus #dan
This question already has answers here:
Create string with trailing spaces in Bash
(2 answers)
Bash LeftPad String with spaces inside variable
(1 answer)
Closed 2 years ago.
Is there a pure bash way to add trailing whitespaces with something like parameter substition in the example above I am using printf in conjunction with command substition witch is not that performant
declare -ir _CONST_VARIABLE_LENGTH='30' _CONST_SUBTRACTOR='3'
declare some_var='here is a string'
declare new_var
new_var="$(printf "%-$((_CONST_VARIABLE_LENGTH-_CONST_SUBTRACTOR))s" "$some_var")"
# what i want, but doesn't work
# ${var:0:LENGTH} only goes till actually length and won't add something if LENGTH is greater than actual var lenght
new_var="${some_var:0:$((_CONST_VARIABLE_LENGTH-_CONST_SUBTRACTOR))}"
This question already has answers here:
Regex: How to match a string that is not only numbers
(11 answers)
Closed 3 years ago.
My code is currently using the following Regular expression which matches on numbers:
/^([^0-9]*)$/
it's working fine when I'm putting Character and Special Character like
hello
merry#
mom&dad
but when I'm trying with a number it's not giving me a proper result
hello 22
mom&dad44
mm88$
I want output like this
1234 - Not Allow
mnb5 - Not Allow
123Hello - Not Allow
Hello123 - Allow
hello - Allow
Hello% - Allow
Hello%123 - Allow
hello 123 - Allow
Hello # - Allow
I want Minimum 3 characters and it does not start with Space and number
Just use this regex without anchors:
/\D/
This will match a non-digit i.e. \D anywhere in a line.
RegEx Demo
This question already has an answer here:
Bash: manipulating with strings (percent sign)
(1 answer)
Closed 6 years ago.
I've got the following variable set in bash:
ver=$(/usr/lib/virtualbox/VBoxManage -v | tail -1)
then I have the following variable which I do not quite understand:
pkg_ver="${ver%%r*}"
Could anyone elaborate on what this does, and how pkg_ver is related to the original ver value?
It is a bash parameter expansion syntax to extract text from end of string upto first occurrence of r
name="Ivory"
printf "%s\n" "${name%%r*}"
Ivo
${PARAMETER%%PATTERN}
This form is to remove the described pattern trying to match it from the end of the string. The operator "%" will try to remove the shortest text matching the pattern, while "%%" tries to do it with the longest text matching.
You will get everything from variable ver until first "r" character and it will be stored inside pkg_ver.
export ver=aaarrr
echo "${ver%%r*}"
aaa
This question already has answers here:
Ruby - replace the first occurrence of a substring with another string
(3 answers)
Closed 6 years ago.
I have this
2016-05-20T13:36:29.835, CTF3D57C
and I want this
2016-05-2013:36:29.835, CTF3D57C
I just want to remove the first T character. How do I do this?
This will substitute the first 'T' in string with anything you want:
str = str.sub('T', '')
If you wish to substitute all occurrence of any substring or regex, use gsub