How to avoid grep command finding commented out strings in the source file?I'm unable to use grep to find strings in a file?Finding certain strings with grep (or similar)How to command grep not to display the searched string?Grep strings in a subgroup of lines in txt fileHow to avoid having newlines with grep -o for multiple match at the same line?Finding the lines with the lowest value in their third column given grep resultsfinding the pattern (ab)* using grepGrep specific strings inside config filehow can i grep something out of a listNeed help on an egrep regex
How I can I roll a number of non-digital dice to get a random number between 1 and 150?
29er Road Tire?
Shutter speed -vs- effective image stabilisation
What are the advantages of luxury car brands like Acura/Lexus over their sibling non-luxury brands Honda/Toyota?
Building a list of products from the elements in another list
Wrong answer from DSolve when solving a differential equation
Do I add my skill check modifier to the roll of 15 granted by Glibness?
What exactly are the `size issues' preventing formation of presheaves being a left adjoint to some forgetful functor?
How to write a 12-bar blues melody
How did the Venus Express detect lightning?
What if the end-user didn't have the required library?
Manager is threatening to grade me poorly if I don't complete the project
Can there be a single technologically advanced nation, in a continent full of non-technologically advanced nations?
US born but as a child of foreign diplomat
List of newcommands used
Are pressure-treated posts that have been submerged for a few days ruined?
Does it make sense for a function to return a rvalue reference
What does "Managed by Windows" do in the Power options for network connection?
In Stroustrup's example, what does this colon mean in `return 1 : 2`? It's not a label or ternary operator
Has a commercial or military jet bi-plane ever been manufactured?
Why does sound not move through a wall?
Why aren't nationalizations in Russia described as socialist?
Did we get closer to another plane than we were supposed to, or was the pilot just protecting our delicate sensibilities?
Is there an idiom that support the idea that "inflation is bad"?
How to avoid grep command finding commented out strings in the source file?
I'm unable to use grep to find strings in a file?Finding certain strings with grep (or similar)How to command grep not to display the searched string?Grep strings in a subgroup of lines in txt fileHow to avoid having newlines with grep -o for multiple match at the same line?Finding the lines with the lowest value in their third column given grep resultsfinding the pattern (ab)* using grepGrep specific strings inside config filehow can i grep something out of a listNeed help on an egrep regex
.everyoneloves__top-leaderboard:empty,.everyoneloves__mid-leaderboard:empty,.everyoneloves__bot-mid-leaderboard:empty margin-bottom:0;
I am running a software where I want to check if miniconda is already installed. Therefore I've checked whether 'miniconda' or 'anaconda' strings in .bashrc file using the grep command. However, it also finds either of above strings which are commented out in the .bashrc file, which I do not want to have. How do I fix this? Relevant part of my bashscript looks as follows.
#Finding if miniconda or anaconda string is in bashrc
if grep -qF -e miniconda -e anaconda "$HOME"/.bashrc ;then
echo "miniconda is found in .bashrc"
I've tested this by adding following lines in the .bashrc file.
#anaconda
#miniconda
Terminal Output
jen@scs400:/scratch$ source bash_script.sh
miniconda is found in .bashrc
scripts grep
|
show 1 more comment
I am running a software where I want to check if miniconda is already installed. Therefore I've checked whether 'miniconda' or 'anaconda' strings in .bashrc file using the grep command. However, it also finds either of above strings which are commented out in the .bashrc file, which I do not want to have. How do I fix this? Relevant part of my bashscript looks as follows.
#Finding if miniconda or anaconda string is in bashrc
if grep -qF -e miniconda -e anaconda "$HOME"/.bashrc ;then
echo "miniconda is found in .bashrc"
I've tested this by adding following lines in the .bashrc file.
#anaconda
#miniconda
Terminal Output
jen@scs400:/scratch$ source bash_script.sh
miniconda is found in .bashrc
scripts grep
2
grep -E '(ana|mini)conda' .bashrc.
– Videonauth
Apr 29 at 16:54
@Videonauth: Thanks it works! But could you please explain why this works?
– Jenny
Apr 29 at 17:03
1
@Videonauth I don't see how that excludes commented lines - doesn't it need some kind of anchor like^[^#]*(ana|mini)conda?
– steeldriver
Apr 29 at 17:09
@steeldriver it doesn't this was just a wild shot in the dark, feel freee to write an exhausting answer if you like.
– Videonauth
Apr 29 at 17:12
Your check for "miniconda is already installed" is incorrect/incomplete. Some users want to switch in and out ofminicondause, and keep the code to do this elsewhere. Some userssource, or., other files from within~/.bashrc,
– waltinator
Apr 29 at 20:00
|
show 1 more comment
I am running a software where I want to check if miniconda is already installed. Therefore I've checked whether 'miniconda' or 'anaconda' strings in .bashrc file using the grep command. However, it also finds either of above strings which are commented out in the .bashrc file, which I do not want to have. How do I fix this? Relevant part of my bashscript looks as follows.
#Finding if miniconda or anaconda string is in bashrc
if grep -qF -e miniconda -e anaconda "$HOME"/.bashrc ;then
echo "miniconda is found in .bashrc"
I've tested this by adding following lines in the .bashrc file.
#anaconda
#miniconda
Terminal Output
jen@scs400:/scratch$ source bash_script.sh
miniconda is found in .bashrc
scripts grep
I am running a software where I want to check if miniconda is already installed. Therefore I've checked whether 'miniconda' or 'anaconda' strings in .bashrc file using the grep command. However, it also finds either of above strings which are commented out in the .bashrc file, which I do not want to have. How do I fix this? Relevant part of my bashscript looks as follows.
#Finding if miniconda or anaconda string is in bashrc
if grep -qF -e miniconda -e anaconda "$HOME"/.bashrc ;then
echo "miniconda is found in .bashrc"
I've tested this by adding following lines in the .bashrc file.
#anaconda
#miniconda
Terminal Output
jen@scs400:/scratch$ source bash_script.sh
miniconda is found in .bashrc
scripts grep
scripts grep
edited Apr 29 at 17:50
αғsнιη
25.1k23100162
25.1k23100162
asked Apr 29 at 16:44
JennyJenny
1189
1189
2
grep -E '(ana|mini)conda' .bashrc.
– Videonauth
Apr 29 at 16:54
@Videonauth: Thanks it works! But could you please explain why this works?
– Jenny
Apr 29 at 17:03
1
@Videonauth I don't see how that excludes commented lines - doesn't it need some kind of anchor like^[^#]*(ana|mini)conda?
– steeldriver
Apr 29 at 17:09
@steeldriver it doesn't this was just a wild shot in the dark, feel freee to write an exhausting answer if you like.
– Videonauth
Apr 29 at 17:12
Your check for "miniconda is already installed" is incorrect/incomplete. Some users want to switch in and out ofminicondause, and keep the code to do this elsewhere. Some userssource, or., other files from within~/.bashrc,
– waltinator
Apr 29 at 20:00
|
show 1 more comment
2
grep -E '(ana|mini)conda' .bashrc.
– Videonauth
Apr 29 at 16:54
@Videonauth: Thanks it works! But could you please explain why this works?
– Jenny
Apr 29 at 17:03
1
@Videonauth I don't see how that excludes commented lines - doesn't it need some kind of anchor like^[^#]*(ana|mini)conda?
– steeldriver
Apr 29 at 17:09
@steeldriver it doesn't this was just a wild shot in the dark, feel freee to write an exhausting answer if you like.
– Videonauth
Apr 29 at 17:12
Your check for "miniconda is already installed" is incorrect/incomplete. Some users want to switch in and out ofminicondause, and keep the code to do this elsewhere. Some userssource, or., other files from within~/.bashrc,
– waltinator
Apr 29 at 20:00
2
2
grep -E '(ana|mini)conda' .bashrc.– Videonauth
Apr 29 at 16:54
grep -E '(ana|mini)conda' .bashrc.– Videonauth
Apr 29 at 16:54
@Videonauth: Thanks it works! But could you please explain why this works?
– Jenny
Apr 29 at 17:03
@Videonauth: Thanks it works! But could you please explain why this works?
– Jenny
Apr 29 at 17:03
1
1
@Videonauth I don't see how that excludes commented lines - doesn't it need some kind of anchor like
^[^#]*(ana|mini)conda?– steeldriver
Apr 29 at 17:09
@Videonauth I don't see how that excludes commented lines - doesn't it need some kind of anchor like
^[^#]*(ana|mini)conda?– steeldriver
Apr 29 at 17:09
@steeldriver it doesn't this was just a wild shot in the dark, feel freee to write an exhausting answer if you like.
– Videonauth
Apr 29 at 17:12
@steeldriver it doesn't this was just a wild shot in the dark, feel freee to write an exhausting answer if you like.
– Videonauth
Apr 29 at 17:12
Your check for "miniconda is already installed" is incorrect/incomplete. Some users want to switch in and out of
miniconda use, and keep the code to do this elsewhere. Some users source, or ., other files from within ~/.bashrc,– waltinator
Apr 29 at 20:00
Your check for "miniconda is already installed" is incorrect/incomplete. Some users want to switch in and out of
miniconda use, and keep the code to do this elsewhere. Some users source, or ., other files from within ~/.bashrc,– waltinator
Apr 29 at 20:00
|
show 1 more comment
1 Answer
1
active
oldest
votes
Try this:
if grep -qwE '^[^#]*(ana|mini)conda' "$HOME"/.bashrc ;then
echo "miniconda/anaconda is found in .bashrc"
fi
New contributor
Comar is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.
Note this won't work reliably, because # can appear as a non-comment character as well.. For example:search_string='#[0-9]+.* anaconda'. Orif [ "$1" -eq 3 ]; then echo "Arg #1 triggered change of target (value was 3)"; target="#$anaconda"; fi. Or evensource '~/#scripts/.anaconda'(or for extremophiles, a shebang I guess:#!/bin/anaconda, or some compiler preprocessor directive marked with a '#' ?!). The OP will have to consider whether such statements are likely to be an issue, though. If it's an issue, your best bet is to detect/filter out static strings using a few chainedsed
– Stilez
Apr 29 at 21:46
add a comment |
Your Answer
StackExchange.ready(function()
var channelOptions =
tags: "".split(" "),
id: "89"
;
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: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
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%2faskubuntu.com%2fquestions%2f1139187%2fhow-to-avoid-grep-command-finding-commented-out-strings-in-the-source-file%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
Try this:
if grep -qwE '^[^#]*(ana|mini)conda' "$HOME"/.bashrc ;then
echo "miniconda/anaconda is found in .bashrc"
fi
New contributor
Comar is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.
Note this won't work reliably, because # can appear as a non-comment character as well.. For example:search_string='#[0-9]+.* anaconda'. Orif [ "$1" -eq 3 ]; then echo "Arg #1 triggered change of target (value was 3)"; target="#$anaconda"; fi. Or evensource '~/#scripts/.anaconda'(or for extremophiles, a shebang I guess:#!/bin/anaconda, or some compiler preprocessor directive marked with a '#' ?!). The OP will have to consider whether such statements are likely to be an issue, though. If it's an issue, your best bet is to detect/filter out static strings using a few chainedsed
– Stilez
Apr 29 at 21:46
add a comment |
Try this:
if grep -qwE '^[^#]*(ana|mini)conda' "$HOME"/.bashrc ;then
echo "miniconda/anaconda is found in .bashrc"
fi
New contributor
Comar is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.
Note this won't work reliably, because # can appear as a non-comment character as well.. For example:search_string='#[0-9]+.* anaconda'. Orif [ "$1" -eq 3 ]; then echo "Arg #1 triggered change of target (value was 3)"; target="#$anaconda"; fi. Or evensource '~/#scripts/.anaconda'(or for extremophiles, a shebang I guess:#!/bin/anaconda, or some compiler preprocessor directive marked with a '#' ?!). The OP will have to consider whether such statements are likely to be an issue, though. If it's an issue, your best bet is to detect/filter out static strings using a few chainedsed
– Stilez
Apr 29 at 21:46
add a comment |
Try this:
if grep -qwE '^[^#]*(ana|mini)conda' "$HOME"/.bashrc ;then
echo "miniconda/anaconda is found in .bashrc"
fi
New contributor
Comar is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.
Try this:
if grep -qwE '^[^#]*(ana|mini)conda' "$HOME"/.bashrc ;then
echo "miniconda/anaconda is found in .bashrc"
fi
New contributor
Comar is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.
edited Apr 29 at 17:27
αғsнιη
25.1k23100162
25.1k23100162
New contributor
Comar is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.
answered Apr 29 at 17:15
ComarComar
4718
4718
New contributor
Comar is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.
New contributor
Comar is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.
Comar is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.
Note this won't work reliably, because # can appear as a non-comment character as well.. For example:search_string='#[0-9]+.* anaconda'. Orif [ "$1" -eq 3 ]; then echo "Arg #1 triggered change of target (value was 3)"; target="#$anaconda"; fi. Or evensource '~/#scripts/.anaconda'(or for extremophiles, a shebang I guess:#!/bin/anaconda, or some compiler preprocessor directive marked with a '#' ?!). The OP will have to consider whether such statements are likely to be an issue, though. If it's an issue, your best bet is to detect/filter out static strings using a few chainedsed
– Stilez
Apr 29 at 21:46
add a comment |
Note this won't work reliably, because # can appear as a non-comment character as well.. For example:search_string='#[0-9]+.* anaconda'. Orif [ "$1" -eq 3 ]; then echo "Arg #1 triggered change of target (value was 3)"; target="#$anaconda"; fi. Or evensource '~/#scripts/.anaconda'(or for extremophiles, a shebang I guess:#!/bin/anaconda, or some compiler preprocessor directive marked with a '#' ?!). The OP will have to consider whether such statements are likely to be an issue, though. If it's an issue, your best bet is to detect/filter out static strings using a few chainedsed
– Stilez
Apr 29 at 21:46
Note this won't work reliably, because # can appear as a non-comment character as well.. For example:
search_string='#[0-9]+.* anaconda' . Or if [ "$1" -eq 3 ]; then echo "Arg #1 triggered change of target (value was 3)"; target="#$anaconda"; fi. Or even source '~/#scripts/.anaconda' (or for extremophiles, a shebang I guess: #!/bin/anaconda, or some compiler preprocessor directive marked with a '#' ?!). The OP will have to consider whether such statements are likely to be an issue, though. If it's an issue, your best bet is to detect/filter out static strings using a few chained sed– Stilez
Apr 29 at 21:46
Note this won't work reliably, because # can appear as a non-comment character as well.. For example:
search_string='#[0-9]+.* anaconda' . Or if [ "$1" -eq 3 ]; then echo "Arg #1 triggered change of target (value was 3)"; target="#$anaconda"; fi. Or even source '~/#scripts/.anaconda' (or for extremophiles, a shebang I guess: #!/bin/anaconda, or some compiler preprocessor directive marked with a '#' ?!). The OP will have to consider whether such statements are likely to be an issue, though. If it's an issue, your best bet is to detect/filter out static strings using a few chained sed– Stilez
Apr 29 at 21:46
add a comment |
Thanks for contributing an answer to Ask Ubuntu!
- 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%2faskubuntu.com%2fquestions%2f1139187%2fhow-to-avoid-grep-command-finding-commented-out-strings-in-the-source-file%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
2
grep -E '(ana|mini)conda' .bashrc.– Videonauth
Apr 29 at 16:54
@Videonauth: Thanks it works! But could you please explain why this works?
– Jenny
Apr 29 at 17:03
1
@Videonauth I don't see how that excludes commented lines - doesn't it need some kind of anchor like
^[^#]*(ana|mini)conda?– steeldriver
Apr 29 at 17:09
@steeldriver it doesn't this was just a wild shot in the dark, feel freee to write an exhausting answer if you like.
– Videonauth
Apr 29 at 17:12
Your check for "miniconda is already installed" is incorrect/incomplete. Some users want to switch in and out of
minicondause, and keep the code to do this elsewhere. Some userssource, or., other files from within~/.bashrc,– waltinator
Apr 29 at 20:00