Search / replace in bash script with dynamic part [closed] - bash

Closed. This question needs debugging details. It is not currently accepting answers.
Edit the question to include desired behavior, a specific problem or error, and the shortest code necessary to reproduce the problem. This will help others answer the question.
Closed 1 year ago.
Improve this question
I'm writing a bash script and I want to edit a PHP config file, find a string and replace by another.
The hard part is that I want this search/replace to be dynamic.
Here is an example:
define('APP_VERSION', '1.0.31');
The goal is to replace 1.0.31 by another version number.
How could I achieve that? I've tried with sed, but can't isolate the version number part (because it's not always the same, so I can't directly search for 1.0.31)
Thanks

The point of regexes is to match non-static text. To replace any version number with 123 use
sed "s/define('APP_VERSION', *'[^']*')/define('APP_VERSION', '123')/"

Related

Checking String within A String For a Directory: Bash Script [closed]

Closed. This question needs debugging details. It is not currently accepting answers.
Edit the question to include desired behavior, a specific problem or error, and the shortest code necessary to reproduce the problem. This will help others answer the question.
Closed 1 year ago.
Improve this question
I am trying to move files from a submissions directory into individual student directories for grading. Below is a screenshot of the script I am trying to use to do this:
My issue is that the if condition does not evaluate to true, even though I know for certain the name variable is contained within the submission file.
Here is an example of line and name:
line: submissions/saundersjacob_hw4.pl
name: jacob
Since 'jacob' is contained within the string 'submissions/saundersjacob_hw4.pl', I wish it to return true, but it does not. Can someone assist me with this?
Please disregard the lines containing echo and my pseudo unimplemented move line after the if statement.
Kind regards,
From bash manual https://www.gnu.org/savannah-checkouts/gnu/bash/manual/bash.html :
[[…]]
[[ expression ]]
When the ‘==’ and ‘!=’ operators are used, the string to the right of the operator is considered a pattern and matched according to the rules described below in Pattern Matching, [...]
Not the string to the left. You can match the left with the pattern on the right, not the other way round.

file substitution based on word matching [closed]

Closed. This question needs debugging details. It is not currently accepting answers.
Edit the question to include desired behavior, a specific problem or error, and the shortest code necessary to reproduce the problem. This will help others answer the question.
Closed 5 years ago.
Improve this question
i have a file say test.sh which contains the following details
check_interval 1
retry_interval 1
event_handler_enabled 1
i want to replace event_handler_enabled 1 line by event_handler_enabled 0
Kindly help
sed -i "s/\(event_handler_enabled.*\)1/\10/" test.sh
Let's see what did sed do:
First, it found the line that you want to change. The line starts with event_handler_enabled(actually it doesn't care how many spaces before).
And then, it found the 1: (\(event_handler_enabled.*\)1)
Finally, it change the 1 to 0.
Done.
P.S. As the back references, it means that sed will find all the characters behind the event_handler_enabled and put them in the right place :)

Storing the object of Select_list [closed]

Closed. This question needs debugging details. It is not currently accepting answers.
Edit the question to include desired behavior, a specific problem or error, and the shortest code necessary to reproduce the problem. This will help others answer the question.
Closed 7 years ago.
Improve this question
Please consider the below code
a=b.select_lists[0]
a.select("Agent")
In the aforementioned code, the first line is taking so much time, So Can anyone tell me Is there any way to store value of "a" object for further use without getting from b.select_lists[0]? Or Is there anyway can we directly get the value of 'a'?
The code which I am trying to write for the select list follows below
<select class="ng-valid ng-dirty" style="" ng-change="selectionsAgentType(AgentType)" ng-model="AgentType"> <select class="ng-valid ng-dirty" ng-change="AgentCategorySelected(agentoptions)" ng-model="agentoptions">
If option with text: 'Agent' is unique on this page.
If you need just simulate select
b.option(:text, 'Agent').select
Also, if you need value of this option
a = b.option(:text, 'Agent').value
Else,
b.select_lists.first.option(:text, 'Agent').select
a = b.select_lists.first.option(:text, 'Agent').value

How do I use include method with the whole alphabet? [closed]

Closed. This question needs debugging details. It is not currently accepting answers.
Edit the question to include desired behavior, a specific problem or error, and the shortest code necessary to reproduce the problem. This will help others answer the question.
Closed 8 years ago.
Improve this question
I want to know if a string includes the form '+#someletter#+', where #someletter# is a
letter. If the string is 'dogs+d+', it would be true because it contains '+d+'. If the string is 'dogs++c', it would be false because the 'c' wasn't surrounded by '+' signs.
I was thinking it was something using regexp like
string.include? '+/a-z/+'
but that doesn't work. Please help.
include? does not accept a regex. To use a regex, you need a different method.
string =~ /\+[a-z]\+/

Many requestShippingRates errors [closed]

Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 8 years ago.
Improve this question
I cannot seem to find out how to track down this bug: I can see it has something to do with Shipping Rates, but there's very little information being posted into the error log.
2013-01-08T15:45:36+01:00 DEBUG (7): requestShippingRates
There are many of these errors being posted.
If you have shell access, try using the following command to search for instances of requestShippingRates. Run it from your /var/www/app directory. the * means look at everyting, the -R means recurse directories, and the -i means ignore upper / lowercase.
grep "requestShippingRates" * -R -i
You did not mention whether or not these errors are showing up in your php log, but you could also grep the following:
grep "error_log(" * -R -i
That will show anything written to the php error log.
There are a couple of possibilities, one is that the string is contained in your code, so simply searching the project for 'requestShippingRates', and find the one that is a string being passed to Mage::log. The other, which is probably more likely, is that at some point somebody has put something along the lines of Mage::log(__FUNCTION__) in one of the requestShippingRates functions. You should be able to find that easy enough by searching for n requestShippingRates (i.e. match the n at the end of a function declaration).

Resources