sed find and replace variation using ^ instead of / [duplicate] - bash

This question already has answers here:
Using different delimiters in sed commands and range addresses
(3 answers)
Closed 2 years ago.
I stumbled upon this variation of sed today in my company's codebase.
Essentially we want to swap out ssh://git# for https:// for our CI.
I found this syntax pretty strange and have not been able to find documentation for it on google... Could someone link me to some documentation or provide some insight?
I see it written this way, with ^ separating the search and replace strings. This has removed the need for the / separator as well as any escapes. Is this maybe a regex trick?
sed 's^ssh://git#^https://^g' -i terraform.tfvars
It performs the same as this. Which is what I would have written originally. But the one above just seems so much cleaner and more readable.
sed 's/ssh:\/\/git#/https:\/\//g' -i terraform.tfvars
Some insight is greatly appreciated! Thanks in advance.

sed manual:
The / characters may be uniformly replaced by any other single character within any given s command. The / character (or whatever other character is used in its stead) can appear in the regexp or replacement only if it is preceded by a \ character.

Related

Use RStudio search replace to replace linebreaks

In the RStudio Search/Replace tool, I am trying to replace two consecutive linebreaks by one. However, I cannot get it to find line breaks with any regex I am aware of - even when I introduce them by replacing something with \n, searching for [\n]+ and similar patterns does not result in any matches. Any suggestions would be much appreciated. (I am on Windows.)

Using BASH, how can I retrieve text between parenthesis?

I've searched for this very question on this site, but either they use REGEX ( I have no clue how to use that in BASH, or it's not quite similar enough of a problem so I can use the examples.
Basically, I have an html file that has the info I need in a set of parenthesis.
for example:
Merry Christmas (english)
Feliz Navidad (spanish)
I'm trying to take the data from the html and put it into either a string or echo it out to a filename for comparison.
Any suggestions?
You question is very vague so it's hard to tell what are exactly your requirements, but the following command will find and print all the parentheses from the file:
grep -oP '\([^)]+\)' input.html

Hi what is the meaning of IFS with single quote in next line?

Hi IFS=' ' is for space, but what is
IFS='
'
It means you are specifying the IFS to use newline for splitting. This would be similar to doing:
IFS=$'\n'
The difference being is that your way is POSIX compliant.
My sources for this answer are here and here
You may find that the different methods are preferred depending on which shell implementation you are using (I think that's the right term?)
NOTE: My answer is based purely on the last 10 minutes of research, I have no prior experience or knowledge with this.

Unix : Optimized command for subsituting words in large file

This question is not related to any code issue. Just need your suggestions.
We have a file which is ~ 100GB and we are applying sed to substitute a few parameters.
This process is taking long time and eating up CPU as well
Can the replacement of sed with awk/tr/perl or any other unix utilities will help in this scenario.
Note:
Any suggestion other than time command.
You can do a couple of things to speed it up:
use fixed pattern matching instead of regexes wherever you can
run sed for example as LANG=C sed '...'
These two are likely to help a lot. Anything else will lead to just minor improvements, even different tools.
About LANG=C - normally the matching is done in whatever encoding your environment is set to which can likely be UTF-8 which causes additional lookups of the UTF-8 characters. If your patterns use just ascii, then definitely go for LANG=C.
Other things that you can try:
if you have to use regexes then use the longest fixed character strings you can - this will allow the regex engine to skip non-matching parts of the file faster (it will skip bigger chunks)
avoid line by line processing if possible - the regex engine will not have to spend time looking for the newline character
Try different AWK's: mawk has been particularly fast for me.

How to unbleach this perl file?

How do I unbleach a Perl file that's been bleached with PAR::Packer::Bleach? The algorithm of bleaching is described in this Stack Overflow answer, however I am unable to make a working script for unbleaching/deobfuscation. Has anybody done this?
EDIT - FIXED: Used print and it worked. What was the problem that bothered me? It was bleached 2 times!!! A bleached file was bleached. So, a double unbleach worked!
PAR::Packer::Bleach uses an algorithm similar to Acme::Bleach.
Here is a discussion of Acme::Bleach that may help you.
As one poster says: "basically Acme::Bleach converts the contents of the code into a bitstring of spaces and tabs on the first run, and then on subsequent runs uncompresses the bitstring and runs the code."
So yes, it should be completely reversible.

Resources