file substitution based on word matching [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 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 :)

Related

Bash sed: Replace first occurrence of string that is alphabetically lower [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 5 days ago.
Improve this question
I'd like to edit a already sorted file by inserting a new line at the correct point.
I'd like to point out that I can not sort the file after just echoing the new line in there since a lot of lines at the bottom of the file are in fact not sorted correctly but should stay that way.
So I was thinking is there an option to use sed or any other command to go through the file line by line and find the first line that is alphabetically lower than my insertion and just insert it there. Maybe awk can do this better?
Thank you very much
Example:
I want to insert A123
Into
A126
A124
A121
A120
So that the output will be
A126
A124
A123
A121
A120

Search / replace in bash script with dynamic part [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'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')/"

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.

replace strings with shell variables in text file [closed]

Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
Closed 4 years ago.
This question was caused by a typo or a problem that can no longer be reproduced. While similar questions may be on-topic here, this one was resolved in a way less likely to help future readers.
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.
Improve this question
I'm writing a shell script in which I've created some variables.
RELEASE="something"
COMMONS="something else"
I've got a file file.txt in which there are some occurrences of $RELEASE and $COMMONS. I want to replace these strings with the corresponding shell variable. I've tried to run (and a lot of other variations):
sed "s|\$RELEASE|${RELEASE}|g" file.txt > result.txt
It replaces "$RELEASE" with "${RELEASE}." Have you any idea how to replace by the value of $RELEASE?
Try this :
sed 's|$RELEASE|'"$RELEASE"'|g' file.txt > result.txt

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