Replacing the multiple values from a string with the values of file in bashshell script problem with using...
Can a paladin prepare more spells if they didn't cast any the previous day?
How to emphasise the insignificance of someone/thing – besides using "klein"
Can I lend at the federal funds rate?
Is there any problem with a full installation on a USB drive?
How many petaflops does it take to land on the moon? What does Artemis need with an Aitken?
A first "Hangman" game in Python
Why does glibc's strlen need to be so complicated to run fast?
Shift lens vs move body?
What is Soda Fountain Etiquette?
Commercial company wants me to list all prior "inventions", give up everything not listed
Why did James Cameron decide to give Alita big eyes?
Why does this London Underground poster from 1924 have a Star of David atop a Christmas tree?
Force SQL Server to use fragmented indexes?
Is the Amazon rainforest the "world's lungs"?
What is the name of this plot that has rows with two connected dots?
Time difference between banns and marriage
Are (c#) dictionaries an Anti Pattern?
Why can't you say don't instead of won't?
Grep contents before a colon
Looking for a plural noun related to ‘fulcrum’ or ‘pivot’ that denotes multiple things as crucial to success
Drawing probabilities on a simplex in TikZ
What was the point of "Substance"?
Is this password scheme legit?
What will be the immediate action by the pilot and ATC if any plane blocks the runway while landing?
Replacing the multiple values from a string with the values of file in bash
shell script problem with using the operatorsMysql output format in Bash Scripti want to extract the value from html tag using sedShell Script: Login to Oracle DB and fetch data to variableUnix variable not able to store sql query outputHow to extract one query at a time from an SQL file?Extracting table data from unevenly spaced text filePrevent Script from Inserting Space in File Name
.everyoneloves__top-leaderboard:empty,.everyoneloves__mid-leaderboard:empty,.everyoneloves__bot-mid-leaderboard:empty{ margin-bottom:0;
}
I have one sql file on which I'm doing cat and assigning to a variable say "SQL". I have different DATABASES and different TABLES in sql file. I'm trying to replace those tables and databases value from the file which have there values stored in it using sed, but I'm getting weird result every time I'm running it.
Below is the approach I've tried:
sql file query:
SELECT *from DATABASE1.TABLE1
UNION ALL
SELECT *from DATABASE2.TABLE2
UNION ALL
SELECT *from DATABASE3.TABLE3
UNION ALL
SELECT *from DATABASE4.TABLE4
.sh file containing database and table details:
#!/bin/bash
DATABASE1="hr"
TABLE1="emp"
DATABASE2="account"
TABLE2="employee_details"
DATABASE3="payable"
TABLE3="job_details"
DATABASE4="dummy"
TABLE4="basic_details"
before using above value I'm sourcing .sh file so that I can get the value details on shell.
SQL=`cat query.sql`
query=$(echo $query | sed -e "s/DATABASE1/${DATABASE1}/;s/DATABASE2/${DATABASE2}/;s/DATABASE3/${DATABASE3}/;s/DATABASE4/${DATABASE4}/;s/TABLE1/${TABLE1}/;s/TABLE2/${TABLE2}/;s/TABLE3/${TABLE3}/;s/TABLE4/${TABLE4}/"
By using above approach I'm getting weird result but when I'm assigning database and table variables on shell and using in above query then I'm able to achieve the desired result.
Please let me know what wrong I'm doing in case of .sh file approach.
bash shell-script sed replace
add a comment |
I have one sql file on which I'm doing cat and assigning to a variable say "SQL". I have different DATABASES and different TABLES in sql file. I'm trying to replace those tables and databases value from the file which have there values stored in it using sed, but I'm getting weird result every time I'm running it.
Below is the approach I've tried:
sql file query:
SELECT *from DATABASE1.TABLE1
UNION ALL
SELECT *from DATABASE2.TABLE2
UNION ALL
SELECT *from DATABASE3.TABLE3
UNION ALL
SELECT *from DATABASE4.TABLE4
.sh file containing database and table details:
#!/bin/bash
DATABASE1="hr"
TABLE1="emp"
DATABASE2="account"
TABLE2="employee_details"
DATABASE3="payable"
TABLE3="job_details"
DATABASE4="dummy"
TABLE4="basic_details"
before using above value I'm sourcing .sh file so that I can get the value details on shell.
SQL=`cat query.sql`
query=$(echo $query | sed -e "s/DATABASE1/${DATABASE1}/;s/DATABASE2/${DATABASE2}/;s/DATABASE3/${DATABASE3}/;s/DATABASE4/${DATABASE4}/;s/TABLE1/${TABLE1}/;s/TABLE2/${TABLE2}/;s/TABLE3/${TABLE3}/;s/TABLE4/${TABLE4}/"
By using above approach I'm getting weird result but when I'm assigning database and table variables on shell and using in above query then I'm able to achieve the desired result.
Please let me know what wrong I'm doing in case of .sh file approach.
bash shell-script sed replace
add a comment |
I have one sql file on which I'm doing cat and assigning to a variable say "SQL". I have different DATABASES and different TABLES in sql file. I'm trying to replace those tables and databases value from the file which have there values stored in it using sed, but I'm getting weird result every time I'm running it.
Below is the approach I've tried:
sql file query:
SELECT *from DATABASE1.TABLE1
UNION ALL
SELECT *from DATABASE2.TABLE2
UNION ALL
SELECT *from DATABASE3.TABLE3
UNION ALL
SELECT *from DATABASE4.TABLE4
.sh file containing database and table details:
#!/bin/bash
DATABASE1="hr"
TABLE1="emp"
DATABASE2="account"
TABLE2="employee_details"
DATABASE3="payable"
TABLE3="job_details"
DATABASE4="dummy"
TABLE4="basic_details"
before using above value I'm sourcing .sh file so that I can get the value details on shell.
SQL=`cat query.sql`
query=$(echo $query | sed -e "s/DATABASE1/${DATABASE1}/;s/DATABASE2/${DATABASE2}/;s/DATABASE3/${DATABASE3}/;s/DATABASE4/${DATABASE4}/;s/TABLE1/${TABLE1}/;s/TABLE2/${TABLE2}/;s/TABLE3/${TABLE3}/;s/TABLE4/${TABLE4}/"
By using above approach I'm getting weird result but when I'm assigning database and table variables on shell and using in above query then I'm able to achieve the desired result.
Please let me know what wrong I'm doing in case of .sh file approach.
bash shell-script sed replace
I have one sql file on which I'm doing cat and assigning to a variable say "SQL". I have different DATABASES and different TABLES in sql file. I'm trying to replace those tables and databases value from the file which have there values stored in it using sed, but I'm getting weird result every time I'm running it.
Below is the approach I've tried:
sql file query:
SELECT *from DATABASE1.TABLE1
UNION ALL
SELECT *from DATABASE2.TABLE2
UNION ALL
SELECT *from DATABASE3.TABLE3
UNION ALL
SELECT *from DATABASE4.TABLE4
.sh file containing database and table details:
#!/bin/bash
DATABASE1="hr"
TABLE1="emp"
DATABASE2="account"
TABLE2="employee_details"
DATABASE3="payable"
TABLE3="job_details"
DATABASE4="dummy"
TABLE4="basic_details"
before using above value I'm sourcing .sh file so that I can get the value details on shell.
SQL=`cat query.sql`
query=$(echo $query | sed -e "s/DATABASE1/${DATABASE1}/;s/DATABASE2/${DATABASE2}/;s/DATABASE3/${DATABASE3}/;s/DATABASE4/${DATABASE4}/;s/TABLE1/${TABLE1}/;s/TABLE2/${TABLE2}/;s/TABLE3/${TABLE3}/;s/TABLE4/${TABLE4}/"
By using above approach I'm getting weird result but when I'm assigning database and table variables on shell and using in above query then I'm able to achieve the desired result.
Please let me know what wrong I'm doing in case of .sh file approach.
bash shell-script sed replace
bash shell-script sed replace
asked 16 mins ago
samsam
488 bronze badges
488 bronze badges
add a comment |
add a comment |
0
active
oldest
votes
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%2f537793%2freplacing-the-multiple-values-from-a-string-with-the-values-of-file-in-bash%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
0
active
oldest
votes
0
active
oldest
votes
active
oldest
votes
active
oldest
votes
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%2f537793%2freplacing-the-multiple-values-from-a-string-with-the-values-of-file-in-bash%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