Sed to discover and replace text BETWEEN two patternsSed: how to replace nextline n symbol in text...
Is it a bad idea to have an pen name with only an initial for a surname?
SQL Server has encountered occurences of I/O requests taking longer than 15 seconds
How to search for Android apps without ads?
How can Caller ID be faked?
Why can't we feel the Earth's revolution?
Is there a risk to write an invitation letter for a stranger to obtain a Czech (Schengen) visa?
Do items with curse of vanishing disappear from shulker boxes?
How to sort human readable size
What is the difference between state-based effects and effects on the stack?
Struggling to present results from long papers in short time slots
How do I become a better writer when I hate reading?
Co-worker is now managing my team. Does this mean that I'm being demoted?
Reflecting Telescope Blind Spot?
Will users know a CardView is clickable
How do credit card companies know what type of business I'm paying for?
Should I worry about having my credit pulled multiple times while car shopping?
Should I email my professor to clear up a (possibly very irrelevant) awkward misunderstanding?
Is it unethical to quit my job during company crisis?
Does the use of English words weaken diceware passphrases
Can artificial satellite positions affect tides?
Cremated People Pottery
Creating polygon with exact measurements in QGIS 3
Manager wants to hire me; HR does not. How to proceed?
How to know whether to write accidentals as sharps or flats?
Sed to discover and replace text BETWEEN two patterns
Sed: how to replace nextline n symbol in text files?replace a character from a string that is in between first and second search using sed or awkReplace one block of text with another block of text when replacement text is in a fileExtract text from one file and replace in the otherReplace content that have newlines using sedsed: replace strings with variable contentGNU Pattern Match and replace exact number of characterssed in bash script with variables returns unterminated errorSed to replace lowercase and capital stringsHow to search and replace with sed in a line with variable content in it?
.everyoneloves__top-leaderboard:empty,.everyoneloves__mid-leaderboard:empty,.everyoneloves__bot-mid-leaderboard:empty{ margin-bottom:0;
}
Dear Stack Exchange Community,
I see other solutions for this but I'm struggling with the regex I need to adapt them to my situation.
I have software-generated files that have lib object member properties with names that I need to replace. I need to use sed to find whatever name of the property, and replace it with the base file name.
Starting with a .js file named bobby.js that contains:
// stage content:
(lib.Scenario2IntroFigure0 = function(mode,startPosition,loop) {
stuff
}
Ending with the same bobby.js file but it now has:
// stage content:
(lib.bobby = function(mode,startPosition,loop) {
stuff
}
NOTE: Scenario2IntroFigure0 is different for every file, unfortunately.
Pseudocode describing what I think I should do:
A. Isolate the old name by looking for whatever is between this pattern::
// stage content:
(lib.
B. And this ending pattern:
= function(mode,startPosition,loop) {
C. Get the file base name itself with:
FILENAME=$(basename $1 '.js')
D. Replace old name with file base name and overwrite the file like:
sed -i "s/Scenario2IntroFigure0/$DA_FILE/g" $1
BUT where "Scenario2IntroFigure0" is whatever sed found between those two patterns.
sed
add a comment |
Dear Stack Exchange Community,
I see other solutions for this but I'm struggling with the regex I need to adapt them to my situation.
I have software-generated files that have lib object member properties with names that I need to replace. I need to use sed to find whatever name of the property, and replace it with the base file name.
Starting with a .js file named bobby.js that contains:
// stage content:
(lib.Scenario2IntroFigure0 = function(mode,startPosition,loop) {
stuff
}
Ending with the same bobby.js file but it now has:
// stage content:
(lib.bobby = function(mode,startPosition,loop) {
stuff
}
NOTE: Scenario2IntroFigure0 is different for every file, unfortunately.
Pseudocode describing what I think I should do:
A. Isolate the old name by looking for whatever is between this pattern::
// stage content:
(lib.
B. And this ending pattern:
= function(mode,startPosition,loop) {
C. Get the file base name itself with:
FILENAME=$(basename $1 '.js')
D. Replace old name with file base name and overwrite the file like:
sed -i "s/Scenario2IntroFigure0/$DA_FILE/g" $1
BUT where "Scenario2IntroFigure0" is whatever sed found between those two patterns.
sed
add a comment |
Dear Stack Exchange Community,
I see other solutions for this but I'm struggling with the regex I need to adapt them to my situation.
I have software-generated files that have lib object member properties with names that I need to replace. I need to use sed to find whatever name of the property, and replace it with the base file name.
Starting with a .js file named bobby.js that contains:
// stage content:
(lib.Scenario2IntroFigure0 = function(mode,startPosition,loop) {
stuff
}
Ending with the same bobby.js file but it now has:
// stage content:
(lib.bobby = function(mode,startPosition,loop) {
stuff
}
NOTE: Scenario2IntroFigure0 is different for every file, unfortunately.
Pseudocode describing what I think I should do:
A. Isolate the old name by looking for whatever is between this pattern::
// stage content:
(lib.
B. And this ending pattern:
= function(mode,startPosition,loop) {
C. Get the file base name itself with:
FILENAME=$(basename $1 '.js')
D. Replace old name with file base name and overwrite the file like:
sed -i "s/Scenario2IntroFigure0/$DA_FILE/g" $1
BUT where "Scenario2IntroFigure0" is whatever sed found between those two patterns.
sed
Dear Stack Exchange Community,
I see other solutions for this but I'm struggling with the regex I need to adapt them to my situation.
I have software-generated files that have lib object member properties with names that I need to replace. I need to use sed to find whatever name of the property, and replace it with the base file name.
Starting with a .js file named bobby.js that contains:
// stage content:
(lib.Scenario2IntroFigure0 = function(mode,startPosition,loop) {
stuff
}
Ending with the same bobby.js file but it now has:
// stage content:
(lib.bobby = function(mode,startPosition,loop) {
stuff
}
NOTE: Scenario2IntroFigure0 is different for every file, unfortunately.
Pseudocode describing what I think I should do:
A. Isolate the old name by looking for whatever is between this pattern::
// stage content:
(lib.
B. And this ending pattern:
= function(mode,startPosition,loop) {
C. Get the file base name itself with:
FILENAME=$(basename $1 '.js')
D. Replace old name with file base name and overwrite the file like:
sed -i "s/Scenario2IntroFigure0/$DA_FILE/g" $1
BUT where "Scenario2IntroFigure0" is whatever sed found between those two patterns.
sed
sed
asked 1 hour ago
mishawagonmishawagon
32
32
add a comment |
add a comment |
1 Answer
1
active
oldest
votes
Replace $file
with your $1
:
file="bobby.js"
filename=$(basename "$file" '.js')
sed -i 's/((lib.).*( = function(mode,startPosition,loop) {)/1'"$filename"'2/' "$file"
add a comment |
Your Answer
StackExchange.ready(function() {
var channelOptions = {
tags: "".split(" "),
id: "106"
};
initTagRenderer("".split(" "), "".split(" "), channelOptions);
StackExchange.using("externalEditor", function() {
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled) {
StackExchange.using("snippets", function() {
createEditor();
});
}
else {
createEditor();
}
});
function createEditor() {
StackExchange.prepareEditor({
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: false,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: null,
bindNavPrevention: true,
postfix: "",
imageUploader: {
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
},
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
});
}
});
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2funix.stackexchange.com%2fquestions%2f524813%2fsed-to-discover-and-replace-text-between-two-patterns%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
1 Answer
1
active
oldest
votes
1 Answer
1
active
oldest
votes
active
oldest
votes
active
oldest
votes
Replace $file
with your $1
:
file="bobby.js"
filename=$(basename "$file" '.js')
sed -i 's/((lib.).*( = function(mode,startPosition,loop) {)/1'"$filename"'2/' "$file"
add a comment |
Replace $file
with your $1
:
file="bobby.js"
filename=$(basename "$file" '.js')
sed -i 's/((lib.).*( = function(mode,startPosition,loop) {)/1'"$filename"'2/' "$file"
add a comment |
Replace $file
with your $1
:
file="bobby.js"
filename=$(basename "$file" '.js')
sed -i 's/((lib.).*( = function(mode,startPosition,loop) {)/1'"$filename"'2/' "$file"
Replace $file
with your $1
:
file="bobby.js"
filename=$(basename "$file" '.js')
sed -i 's/((lib.).*( = function(mode,startPosition,loop) {)/1'"$filename"'2/' "$file"
answered 1 hour ago
FreddyFreddy
4,7531521
4,7531521
add a comment |
add a comment |
Thanks for contributing an answer to Unix & Linux Stack Exchange!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2funix.stackexchange.com%2fquestions%2f524813%2fsed-to-discover-and-replace-text-between-two-patterns%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown