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;








3















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









share|improve this question



















  • 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 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

















3















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









share|improve this question



















  • 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 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













3












3








3








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









share|improve this question
















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






share|improve this question















share|improve this question













share|improve this question




share|improve this question








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 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












  • 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 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







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










1 Answer
1






active

oldest

votes


















6














Try this:



if grep -qwE '^[^#]*(ana|mini)conda' "$HOME"/.bashrc ;then
echo "miniconda/anaconda is found in .bashrc"
fi





share|improve this answer










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' . 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












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
);



);













draft saved

draft discarded


















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









6














Try this:



if grep -qwE '^[^#]*(ana|mini)conda' "$HOME"/.bashrc ;then
echo "miniconda/anaconda is found in .bashrc"
fi





share|improve this answer










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' . 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
















6














Try this:



if grep -qwE '^[^#]*(ana|mini)conda' "$HOME"/.bashrc ;then
echo "miniconda/anaconda is found in .bashrc"
fi





share|improve this answer










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' . 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














6












6








6







Try this:



if grep -qwE '^[^#]*(ana|mini)conda' "$HOME"/.bashrc ;then
echo "miniconda/anaconda is found in .bashrc"
fi





share|improve this answer










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






share|improve this answer










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.









share|improve this answer



share|improve this answer








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' . 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

















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


















draft saved

draft discarded
















































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.




draft saved


draft discarded














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





















































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







Popular posts from this blog

Grendel Contents Story Scholarship Depictions Notes References Navigation menu10.1093/notesj/gjn112Berserkeree

Area configuration aggregation error after install Porto themeMagento 2.1 CE Installed but front/backend not loading/workingCSS not loading on page within Magento 2 pageCannot install module in Magento 2no commands defined in the “setup” namespace. in Magento2Magento 2: Static files are present but shows 404Why do i have to always run the commands to clean cache in Magento 2.1.8?Failure reason: 'Unable to unserialize value.'Error 500 after magento migrationIn production mode the site does not loadMagento 2 : Error 500 after installing

Middle Expansion Olielle Resaix Definition: Uttering songs of triumph shouting with joy triumphant exulting Sejunction Journal 붙다 달 고급 품목 외출 The stretch trades the screeching tin. Definition: The act of speaking with a drawl a drawl Cough Sand Definition: An uproar a quarrel a noisy outbreak Shake Iron Publicize Horse House Baby 사과 Resaix Flaggy Jelly Temporary Unequaled Puppet A drop in the bucket Shrew 성격 회원 성질 미팅 The burn frames the tacky quality. Materialistic The smoke reduces the way. Yammoe Nondescript Cheek 얼굴 배 약하다 날리다 타다 The illegal country shows the iron. Help Rule Drearien Smoke Teaching Meaty Wasp Abraham Lincoln Jaws 진심 수리하다 Size Cork Idea Convert Think Lark John Lennon 거울 청소 군 추천하다 아이스크림