Grep quotation mark inside quotation markgrep on a variableHow to grep -v and also exclude the next line...

Is there any practical application for performing a double Fourier transform? ...or an inverse Fourier transform on a time-domain input?

How would you identify when an object in a Lissajous orbit needs station keeping?

How do I get a decreased-by-one x in a foreach loop?

Couple of slangs I've heard when watching anime

Is a player able to change alignment midway through an adventure?

Why in most German places is the church the tallest building?

Handling Disruptive Student on the Autistic Spectrum

What is the difference between Major and Minor Bug?

Did a flight controller ever answer Flight with a no-go?

Can a Rogue PC teach an NPC to perform Sneak Attack?

Examples of topos that are not ordinary spaces

Anatomically Correct Whomping Willow

How to find out the average duration of the peer-review process for a given journal?

An interview question: What's the number of String objects being created?

Is there any music source code for sound chips?

How do I get toddlers to stop asking for food every hour?

How should I face my manager if I make a mistake because a senior coworker explained something incorrectly to me?

Why would an IIS hosted site prompt for AD account credential if accessed through a hostname or IP, but not through servername?

Algorithms vs LP or MIP

How is the idea of "two people having a heated argument" idiomatically expressed in German?

Why did Khan ask Admiral James T. Kirk about Project Genesis?

Why did this happen to Thanos's ships at the end of "Avengers: Endgame"?

Is “I am getting married with my sister” ambiguous?

Is "The life is beautiful" incorrect or just very non-idiomatic?



Grep quotation mark inside quotation mark


grep on a variableHow to grep -v and also exclude the next line after the match?Show ratio for all available resolutionsGrep lines before after if value of a string is greater than zeroUnexpected grep behaviour when using command substituitonHow to search for all tabs between two quotation marks with grep / egrep






.everyoneloves__top-leaderboard:empty,.everyoneloves__mid-leaderboard:empty,.everyoneloves__bot-mid-leaderboard:empty{ margin-bottom:0;
}







-1















example.txt



alias znm="base64"
alias asu="sed 's/.{4}/&™/g'"
alias mmk="sed 's/(.{4})™/1/g'"
alias mmk="sed 's/(.{8})™/1/g'"


Desired output:



alias asu="sed 's/.{4}/&™/g'"


But it's get error when i tried this



grep -wo "alias asu="sed 's/.{4}/&™/g'"" example.txt


How to do it correctly?










share|improve this question






















  • 1





    Why not just grep asu example.txt or awk 'NR==2' example.txt?

    – Nasir Riley
    yesterday






  • 1





    The first command with grep will give you that entire line which is your desired output. Have you tried using it?

    – Nasir Riley
    yesterday








  • 1





    No, you don't. The command that I just gave you returns the output that you want. You are complicating something that's very simple.

    – Nasir Riley
    yesterday








  • 1





    @NasirRiley It would output whatever is on the second line, no matter what that was. I'm imagining that they want to test whether the particular alias is in the file (with an exact alias definition).

    – Kusalananda
    yesterday






  • 2





    @Kusalananda I understand that but the grep command gives the expected output as they confirmed. If they wanted that exact alias then that should have been specified in the question. With the way that it's written, that information is being obfuscated.

    – Nasir Riley
    yesterday




















-1















example.txt



alias znm="base64"
alias asu="sed 's/.{4}/&™/g'"
alias mmk="sed 's/(.{4})™/1/g'"
alias mmk="sed 's/(.{8})™/1/g'"


Desired output:



alias asu="sed 's/.{4}/&™/g'"


But it's get error when i tried this



grep -wo "alias asu="sed 's/.{4}/&™/g'"" example.txt


How to do it correctly?










share|improve this question






















  • 1





    Why not just grep asu example.txt or awk 'NR==2' example.txt?

    – Nasir Riley
    yesterday






  • 1





    The first command with grep will give you that entire line which is your desired output. Have you tried using it?

    – Nasir Riley
    yesterday








  • 1





    No, you don't. The command that I just gave you returns the output that you want. You are complicating something that's very simple.

    – Nasir Riley
    yesterday








  • 1





    @NasirRiley It would output whatever is on the second line, no matter what that was. I'm imagining that they want to test whether the particular alias is in the file (with an exact alias definition).

    – Kusalananda
    yesterday






  • 2





    @Kusalananda I understand that but the grep command gives the expected output as they confirmed. If they wanted that exact alias then that should have been specified in the question. With the way that it's written, that information is being obfuscated.

    – Nasir Riley
    yesterday
















-1












-1








-1








example.txt



alias znm="base64"
alias asu="sed 's/.{4}/&™/g'"
alias mmk="sed 's/(.{4})™/1/g'"
alias mmk="sed 's/(.{8})™/1/g'"


Desired output:



alias asu="sed 's/.{4}/&™/g'"


But it's get error when i tried this



grep -wo "alias asu="sed 's/.{4}/&™/g'"" example.txt


How to do it correctly?










share|improve this question
















example.txt



alias znm="base64"
alias asu="sed 's/.{4}/&™/g'"
alias mmk="sed 's/(.{4})™/1/g'"
alias mmk="sed 's/(.{8})™/1/g'"


Desired output:



alias asu="sed 's/.{4}/&™/g'"


But it's get error when i tried this



grep -wo "alias asu="sed 's/.{4}/&™/g'"" example.txt


How to do it correctly?







bash shell text-processing






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited yesterday







IISomeOneII

















asked yesterday









IISomeOneIIIISomeOneII

1321 silver badge13 bronze badges




1321 silver badge13 bronze badges











  • 1





    Why not just grep asu example.txt or awk 'NR==2' example.txt?

    – Nasir Riley
    yesterday






  • 1





    The first command with grep will give you that entire line which is your desired output. Have you tried using it?

    – Nasir Riley
    yesterday








  • 1





    No, you don't. The command that I just gave you returns the output that you want. You are complicating something that's very simple.

    – Nasir Riley
    yesterday








  • 1





    @NasirRiley It would output whatever is on the second line, no matter what that was. I'm imagining that they want to test whether the particular alias is in the file (with an exact alias definition).

    – Kusalananda
    yesterday






  • 2





    @Kusalananda I understand that but the grep command gives the expected output as they confirmed. If they wanted that exact alias then that should have been specified in the question. With the way that it's written, that information is being obfuscated.

    – Nasir Riley
    yesterday
















  • 1





    Why not just grep asu example.txt or awk 'NR==2' example.txt?

    – Nasir Riley
    yesterday






  • 1





    The first command with grep will give you that entire line which is your desired output. Have you tried using it?

    – Nasir Riley
    yesterday








  • 1





    No, you don't. The command that I just gave you returns the output that you want. You are complicating something that's very simple.

    – Nasir Riley
    yesterday








  • 1





    @NasirRiley It would output whatever is on the second line, no matter what that was. I'm imagining that they want to test whether the particular alias is in the file (with an exact alias definition).

    – Kusalananda
    yesterday






  • 2





    @Kusalananda I understand that but the grep command gives the expected output as they confirmed. If they wanted that exact alias then that should have been specified in the question. With the way that it's written, that information is being obfuscated.

    – Nasir Riley
    yesterday










1




1





Why not just grep asu example.txt or awk 'NR==2' example.txt?

– Nasir Riley
yesterday





Why not just grep asu example.txt or awk 'NR==2' example.txt?

– Nasir Riley
yesterday




1




1





The first command with grep will give you that entire line which is your desired output. Have you tried using it?

– Nasir Riley
yesterday







The first command with grep will give you that entire line which is your desired output. Have you tried using it?

– Nasir Riley
yesterday






1




1





No, you don't. The command that I just gave you returns the output that you want. You are complicating something that's very simple.

– Nasir Riley
yesterday







No, you don't. The command that I just gave you returns the output that you want. You are complicating something that's very simple.

– Nasir Riley
yesterday






1




1





@NasirRiley It would output whatever is on the second line, no matter what that was. I'm imagining that they want to test whether the particular alias is in the file (with an exact alias definition).

– Kusalananda
yesterday





@NasirRiley It would output whatever is on the second line, no matter what that was. I'm imagining that they want to test whether the particular alias is in the file (with an exact alias definition).

– Kusalananda
yesterday




2




2





@Kusalananda I understand that but the grep command gives the expected output as they confirmed. If they wanted that exact alias then that should have been specified in the question. With the way that it's written, that information is being obfuscated.

– Nasir Riley
yesterday







@Kusalananda I understand that but the grep command gives the expected output as they confirmed. If they wanted that exact alias then that should have been specified in the question. With the way that it's written, that information is being obfuscated.

– Nasir Riley
yesterday












1 Answer
1






active

oldest

votes


















1















grep -Fx -f /dev/stdin example.txt <<'PATTERN'
alias asu="sed 's/.{4}/&™/g'"
PATTERN


This avoids the issues that you're having with the quotes and regular expression characters and passes the pattern as is into grep on standard input. The grep utility reads the pattern from standard input because we've asked it, with -f /dev/stdin, to do that (on Android, you may instead use -f /dev/fd/0).



The -F uses the pattern as a string instead of as a regular expression, and -x ensures that we only matches lines that matches the pattern completely (as if the pattern was anchored to both start and finish of the line).



Using this as a test for whether that particular alias is in the file:



if grep -q -Fx -f /dev/stdin example.txt; then
echo the alias is there
else
echo the alias is not there
fi <<'PATTERN'
alias asu="sed 's/.{4}/&™/g'"
PATTERN




Your command,



grep -wo "alias asu="sed 's/.{4}/&™/g'"" example.txt


is really calling grep with a pattern and two filenames:





  • "alias asu="sed is the pattern (really, a regular expression, as you don't use -F).


  • 's/.{4}/&™/g'"" is the first filename since the shell will break the string on the unquoted space.


  • example.txt is the second filename.


You could obviously make sure to quote all special characters and quotes, but using a here-document is slightly easier as you don't have to modify the pattern at all.






share|improve this answer




























  • grep: /dev/stdin: No such file or directory | It's not work, am i doing it wrong

    – IISomeOneII
    yesterday








  • 1





    @IISomeOneII Oh, that's interesting! Are you on an AIX system? What does uname -a say?

    – Kusalananda
    yesterday











  • Linux localhost 3.18.31-perf-g653a83a #1 SMP PREEMPT Mon Jan 28 10:05:53 WIB 2019 aarch64 Android

    – IISomeOneII
    yesterday






  • 1





    @IISomeOneII Hmmm... Could you try with /proc/self/fd/0 in place of /dev/stdin? I'm not aware of how Linux works on Android devices. I'm testing this on Ubuntu Linux and OpenBSD, and both provides /dev/stdin. The other possibility is that you mistyped something.

    – Kusalananda
    yesterday






  • 1





    @IISomeOneII Yes, /dev/fd/0 or /proc/self/fd/0 should work on Android.

    – Kusalananda
    yesterday














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


}
});














draft saved

draft discarded


















StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2funix.stackexchange.com%2fquestions%2f536781%2fgrep-quotation-mark-inside-quotation-mark%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









1















grep -Fx -f /dev/stdin example.txt <<'PATTERN'
alias asu="sed 's/.{4}/&™/g'"
PATTERN


This avoids the issues that you're having with the quotes and regular expression characters and passes the pattern as is into grep on standard input. The grep utility reads the pattern from standard input because we've asked it, with -f /dev/stdin, to do that (on Android, you may instead use -f /dev/fd/0).



The -F uses the pattern as a string instead of as a regular expression, and -x ensures that we only matches lines that matches the pattern completely (as if the pattern was anchored to both start and finish of the line).



Using this as a test for whether that particular alias is in the file:



if grep -q -Fx -f /dev/stdin example.txt; then
echo the alias is there
else
echo the alias is not there
fi <<'PATTERN'
alias asu="sed 's/.{4}/&™/g'"
PATTERN




Your command,



grep -wo "alias asu="sed 's/.{4}/&™/g'"" example.txt


is really calling grep with a pattern and two filenames:





  • "alias asu="sed is the pattern (really, a regular expression, as you don't use -F).


  • 's/.{4}/&™/g'"" is the first filename since the shell will break the string on the unquoted space.


  • example.txt is the second filename.


You could obviously make sure to quote all special characters and quotes, but using a here-document is slightly easier as you don't have to modify the pattern at all.






share|improve this answer




























  • grep: /dev/stdin: No such file or directory | It's not work, am i doing it wrong

    – IISomeOneII
    yesterday








  • 1





    @IISomeOneII Oh, that's interesting! Are you on an AIX system? What does uname -a say?

    – Kusalananda
    yesterday











  • Linux localhost 3.18.31-perf-g653a83a #1 SMP PREEMPT Mon Jan 28 10:05:53 WIB 2019 aarch64 Android

    – IISomeOneII
    yesterday






  • 1





    @IISomeOneII Hmmm... Could you try with /proc/self/fd/0 in place of /dev/stdin? I'm not aware of how Linux works on Android devices. I'm testing this on Ubuntu Linux and OpenBSD, and both provides /dev/stdin. The other possibility is that you mistyped something.

    – Kusalananda
    yesterday






  • 1





    @IISomeOneII Yes, /dev/fd/0 or /proc/self/fd/0 should work on Android.

    – Kusalananda
    yesterday
















1















grep -Fx -f /dev/stdin example.txt <<'PATTERN'
alias asu="sed 's/.{4}/&™/g'"
PATTERN


This avoids the issues that you're having with the quotes and regular expression characters and passes the pattern as is into grep on standard input. The grep utility reads the pattern from standard input because we've asked it, with -f /dev/stdin, to do that (on Android, you may instead use -f /dev/fd/0).



The -F uses the pattern as a string instead of as a regular expression, and -x ensures that we only matches lines that matches the pattern completely (as if the pattern was anchored to both start and finish of the line).



Using this as a test for whether that particular alias is in the file:



if grep -q -Fx -f /dev/stdin example.txt; then
echo the alias is there
else
echo the alias is not there
fi <<'PATTERN'
alias asu="sed 's/.{4}/&™/g'"
PATTERN




Your command,



grep -wo "alias asu="sed 's/.{4}/&™/g'"" example.txt


is really calling grep with a pattern and two filenames:





  • "alias asu="sed is the pattern (really, a regular expression, as you don't use -F).


  • 's/.{4}/&™/g'"" is the first filename since the shell will break the string on the unquoted space.


  • example.txt is the second filename.


You could obviously make sure to quote all special characters and quotes, but using a here-document is slightly easier as you don't have to modify the pattern at all.






share|improve this answer




























  • grep: /dev/stdin: No such file or directory | It's not work, am i doing it wrong

    – IISomeOneII
    yesterday








  • 1





    @IISomeOneII Oh, that's interesting! Are you on an AIX system? What does uname -a say?

    – Kusalananda
    yesterday











  • Linux localhost 3.18.31-perf-g653a83a #1 SMP PREEMPT Mon Jan 28 10:05:53 WIB 2019 aarch64 Android

    – IISomeOneII
    yesterday






  • 1





    @IISomeOneII Hmmm... Could you try with /proc/self/fd/0 in place of /dev/stdin? I'm not aware of how Linux works on Android devices. I'm testing this on Ubuntu Linux and OpenBSD, and both provides /dev/stdin. The other possibility is that you mistyped something.

    – Kusalananda
    yesterday






  • 1





    @IISomeOneII Yes, /dev/fd/0 or /proc/self/fd/0 should work on Android.

    – Kusalananda
    yesterday














1














1










1









grep -Fx -f /dev/stdin example.txt <<'PATTERN'
alias asu="sed 's/.{4}/&™/g'"
PATTERN


This avoids the issues that you're having with the quotes and regular expression characters and passes the pattern as is into grep on standard input. The grep utility reads the pattern from standard input because we've asked it, with -f /dev/stdin, to do that (on Android, you may instead use -f /dev/fd/0).



The -F uses the pattern as a string instead of as a regular expression, and -x ensures that we only matches lines that matches the pattern completely (as if the pattern was anchored to both start and finish of the line).



Using this as a test for whether that particular alias is in the file:



if grep -q -Fx -f /dev/stdin example.txt; then
echo the alias is there
else
echo the alias is not there
fi <<'PATTERN'
alias asu="sed 's/.{4}/&™/g'"
PATTERN




Your command,



grep -wo "alias asu="sed 's/.{4}/&™/g'"" example.txt


is really calling grep with a pattern and two filenames:





  • "alias asu="sed is the pattern (really, a regular expression, as you don't use -F).


  • 's/.{4}/&™/g'"" is the first filename since the shell will break the string on the unquoted space.


  • example.txt is the second filename.


You could obviously make sure to quote all special characters and quotes, but using a here-document is slightly easier as you don't have to modify the pattern at all.






share|improve this answer















grep -Fx -f /dev/stdin example.txt <<'PATTERN'
alias asu="sed 's/.{4}/&™/g'"
PATTERN


This avoids the issues that you're having with the quotes and regular expression characters and passes the pattern as is into grep on standard input. The grep utility reads the pattern from standard input because we've asked it, with -f /dev/stdin, to do that (on Android, you may instead use -f /dev/fd/0).



The -F uses the pattern as a string instead of as a regular expression, and -x ensures that we only matches lines that matches the pattern completely (as if the pattern was anchored to both start and finish of the line).



Using this as a test for whether that particular alias is in the file:



if grep -q -Fx -f /dev/stdin example.txt; then
echo the alias is there
else
echo the alias is not there
fi <<'PATTERN'
alias asu="sed 's/.{4}/&™/g'"
PATTERN




Your command,



grep -wo "alias asu="sed 's/.{4}/&™/g'"" example.txt


is really calling grep with a pattern and two filenames:





  • "alias asu="sed is the pattern (really, a regular expression, as you don't use -F).


  • 's/.{4}/&™/g'"" is the first filename since the shell will break the string on the unquoted space.


  • example.txt is the second filename.


You could obviously make sure to quote all special characters and quotes, but using a here-document is slightly easier as you don't have to modify the pattern at all.







share|improve this answer














share|improve this answer



share|improve this answer








edited yesterday

























answered yesterday









KusalanandaKusalananda

161k18 gold badges318 silver badges505 bronze badges




161k18 gold badges318 silver badges505 bronze badges
















  • grep: /dev/stdin: No such file or directory | It's not work, am i doing it wrong

    – IISomeOneII
    yesterday








  • 1





    @IISomeOneII Oh, that's interesting! Are you on an AIX system? What does uname -a say?

    – Kusalananda
    yesterday











  • Linux localhost 3.18.31-perf-g653a83a #1 SMP PREEMPT Mon Jan 28 10:05:53 WIB 2019 aarch64 Android

    – IISomeOneII
    yesterday






  • 1





    @IISomeOneII Hmmm... Could you try with /proc/self/fd/0 in place of /dev/stdin? I'm not aware of how Linux works on Android devices. I'm testing this on Ubuntu Linux and OpenBSD, and both provides /dev/stdin. The other possibility is that you mistyped something.

    – Kusalananda
    yesterday






  • 1





    @IISomeOneII Yes, /dev/fd/0 or /proc/self/fd/0 should work on Android.

    – Kusalananda
    yesterday



















  • grep: /dev/stdin: No such file or directory | It's not work, am i doing it wrong

    – IISomeOneII
    yesterday








  • 1





    @IISomeOneII Oh, that's interesting! Are you on an AIX system? What does uname -a say?

    – Kusalananda
    yesterday











  • Linux localhost 3.18.31-perf-g653a83a #1 SMP PREEMPT Mon Jan 28 10:05:53 WIB 2019 aarch64 Android

    – IISomeOneII
    yesterday






  • 1





    @IISomeOneII Hmmm... Could you try with /proc/self/fd/0 in place of /dev/stdin? I'm not aware of how Linux works on Android devices. I'm testing this on Ubuntu Linux and OpenBSD, and both provides /dev/stdin. The other possibility is that you mistyped something.

    – Kusalananda
    yesterday






  • 1





    @IISomeOneII Yes, /dev/fd/0 or /proc/self/fd/0 should work on Android.

    – Kusalananda
    yesterday

















grep: /dev/stdin: No such file or directory | It's not work, am i doing it wrong

– IISomeOneII
yesterday







grep: /dev/stdin: No such file or directory | It's not work, am i doing it wrong

– IISomeOneII
yesterday






1




1





@IISomeOneII Oh, that's interesting! Are you on an AIX system? What does uname -a say?

– Kusalananda
yesterday





@IISomeOneII Oh, that's interesting! Are you on an AIX system? What does uname -a say?

– Kusalananda
yesterday













Linux localhost 3.18.31-perf-g653a83a #1 SMP PREEMPT Mon Jan 28 10:05:53 WIB 2019 aarch64 Android

– IISomeOneII
yesterday





Linux localhost 3.18.31-perf-g653a83a #1 SMP PREEMPT Mon Jan 28 10:05:53 WIB 2019 aarch64 Android

– IISomeOneII
yesterday




1




1





@IISomeOneII Hmmm... Could you try with /proc/self/fd/0 in place of /dev/stdin? I'm not aware of how Linux works on Android devices. I'm testing this on Ubuntu Linux and OpenBSD, and both provides /dev/stdin. The other possibility is that you mistyped something.

– Kusalananda
yesterday





@IISomeOneII Hmmm... Could you try with /proc/self/fd/0 in place of /dev/stdin? I'm not aware of how Linux works on Android devices. I'm testing this on Ubuntu Linux and OpenBSD, and both provides /dev/stdin. The other possibility is that you mistyped something.

– Kusalananda
yesterday




1




1





@IISomeOneII Yes, /dev/fd/0 or /proc/self/fd/0 should work on Android.

– Kusalananda
yesterday





@IISomeOneII Yes, /dev/fd/0 or /proc/self/fd/0 should work on Android.

– Kusalananda
yesterday


















draft saved

draft discarded




















































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.




draft saved


draft discarded














StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2funix.stackexchange.com%2fquestions%2f536781%2fgrep-quotation-mark-inside-quotation-mark%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

Taj Mahal Inhaltsverzeichnis Aufbau | Geschichte | 350-Jahr-Feier | Heutige Bedeutung | Siehe auch |...

Baia Sprie Cuprins Etimologie | Istorie | Demografie | Politică și administrație | Arii naturale...

Nicolae Petrescu-Găină Cuprins Biografie | Opera | In memoriam | Varia | Controverse, incertitudini...