Search and replace string in unix bash regex [duplicate] - bash

This question already has answers here:
Replacing some characters in a string with another character
(6 answers)
Closed 9 years ago.
Does anyone have an idea on how to search and replace in a string? Let's say for example I have a string
string=".blah http://google.com.ph/tabs/1.5.8 setup https://yahoo.com.ph/root/blah"
I want to search for version 1.5.8 and then replace it with 1.5.9. How do i do it in bash?

instring="version 1.5.8"
outstring=${instring//1.5.8/1.5.9}

Related

How to split a string by space and newline in Golang? [duplicate]

This question already has answers here:
Split a string on whitespace in Go?
(4 answers)
Closed 10 months ago.
I'm a beginner in Golang and I want to split a multiline text terminated by the EOF indicator, and I want to do it by the space and the presence of new lines ( since the user is gonna press "enter" a lot ).
Any idea of how?
Use strings.Fields
words := strings.Fields(someString)
See example in The Go Playground

When trying to escape apostrophe with 'gsub', I get backreference [duplicate]

This question already has answers here:
Why does String#gsub double content?
(3 answers)
Closed 5 years ago.
I have this code:
"1'2".gsub("'","\\'")
Instead of "1\'2", I get: "122". Why?
You need to use this:
puts "1'2".gsub("'","\\\\'")
It is because "\\'" means the context following the match, which is "2".

How to remove lines from a file using a list of strings [duplicate]

This question already has answers here:
Deleting lines from one file which are in another file
(11 answers)
How to delete from a text file, all lines that contain a specific string?
(21 answers)
Closed 6 years ago.
I have a file which contains 100 000 entries and have to search for existence of 2000 different strings. If the string exists then I have to remove that line. Is there any way to do this?

/.../ What does this Ruby regex mean? [duplicate]

This question already has an answer here:
Reference - What does this regex mean?
(1 answer)
Closed 8 years ago.
What does this Ruby regex mean?
/.../
This regex matches any three characters.

Ruby: what is the '=~' operator [duplicate]

This question already has answers here:
ruby operator "=~" [duplicate]
(3 answers)
Closed 9 years ago.
I was wondering if anyone could explain what the =~ operator does in Ruby. I have seen it a few times but am unable to find a proper explanation of it.
It is used to match Regexes against strings:
http://www.ruby-doc.org/core-2.0.0/Regexp.html#method-i-3D-7E
It returns either a Integer value of the first occurrence in the string or if the expression doesn't match the String it returns nil.

Resources