shell - display number of errors for best matches in agrepCheck if a directory exists in a shell scriptGet program execution time in the shellHow to run a shell script on a Unix console or Mac terminal?In the shell, what does “ 2>&1 ” mean?Aborting a shell script if any command returns a non-zero value?Automatic exit from bash shell script on errorHow to specify the private SSH-key to use when executing shell command on Git?When do we need curly braces around shell variables?Replace one substring for another string in shell scriptHow do I pause my shell script for a second before continuing?
Count All Possible Unique Combinations of Letters in a Word
What happens to Cessna electric flaps that are moving when power is lost?
Prime sieve in Python
What is the legal status of travelling with methadone in your carry-on?
Are all instances of trolls turning to stone ultimately references back to Tolkien?
How did Bellatrix know about the Philosopher's Stone?
How does a blind passenger not die, if driver becomes unconscious
Hot coffee brewing solutions for deep woods camping
Why do even high-end cameras often still include normal (non-cross-type) AF sensors?
How large would a mega structure have to be to host 1 billion people indefinitely?
When to remove insignificant variables?
Would it be a copyright violation if I made a character’s full name refer to a song?
Is there a term for the belief that "if it's legal, it's moral"?
What did River say when she woke from her proto-comatose state?
Does having had a visa for a country mean I used to be a citizen/national of that country?
Is a single radon-daughter atom in air a solid?
Why do all the teams that I have worked with always finish a sprint without completion of all the stories?
Why is prior to creation called holy?
Greeting with "Ho"
Is it illegal to withhold someone's passport and green card in California?
Should developer taking test phones home or put in office?
Suggested order for Amazon Prime Doctor Who series
Can Ogre clerics use Purify Food and Drink on humanoid characters?
What size of powerbank will I need to power a phone and DSLR for 2 weeks?
shell - display number of errors for best matches in agrep
Check if a directory exists in a shell scriptGet program execution time in the shellHow to run a shell script on a Unix console or Mac terminal?In the shell, what does “ 2>&1 ” mean?Aborting a shell script if any command returns a non-zero value?Automatic exit from bash shell script on errorHow to specify the private SSH-key to use when executing shell command on Git?When do we need curly braces around shell variables?Replace one substring for another string in shell scriptHow do I pause my shell script for a second before continuing?
.everyoneloves__top-leaderboard:empty,.everyoneloves__mid-leaderboard:empty,.everyoneloves__bot-mid-leaderboard:empty height:90px;width:728px;box-sizing:border-box;
What I am trying to do is to get the best-matching word in a file and the number of errors for it using agrep
. For now I am only able to get the word using this script:
array=(bla1 bla2 bla3)
for eachWord in "$array[@]"; do
result=$(yes "yes" | agrep -B $eachWord /home/victoria/file.txt)
printf "$resultn"
done
Where bla1,2,3 are some words.
The output I have is the following:
agrep: 4 words match within 2 errors; search for them? (y/n)counting
first
and
should
agrep: 1 word matches within 1 error; search for it? (y/n)should
agrep: 2 words match within 4 errors; search for them? (y/n)must
must
agrep: 1 word matches within 2 errors; search for it? (y/n)should
Is there any way I can have the number of errors (2,1,4,2 in the output example above)?
linux bash shell grep agrep
add a comment |
What I am trying to do is to get the best-matching word in a file and the number of errors for it using agrep
. For now I am only able to get the word using this script:
array=(bla1 bla2 bla3)
for eachWord in "$array[@]"; do
result=$(yes "yes" | agrep -B $eachWord /home/victoria/file.txt)
printf "$resultn"
done
Where bla1,2,3 are some words.
The output I have is the following:
agrep: 4 words match within 2 errors; search for them? (y/n)counting
first
and
should
agrep: 1 word matches within 1 error; search for it? (y/n)should
agrep: 2 words match within 4 errors; search for them? (y/n)must
must
agrep: 1 word matches within 2 errors; search for it? (y/n)should
Is there any way I can have the number of errors (2,1,4,2 in the output example above)?
linux bash shell grep agrep
What do you want with it?
– Inian
Mar 25 at 8:58
the Levenstein distance for mine and the best-matching word
– Victoria
Mar 25 at 9:24
1
As far as i've understood, you want the output to be: 2 1 4 2(i.e, number of errors). Can you try this:result=$(yes "yes" | agrep -B $eachWord /home/victoria/file.txt|sed -E -n 's/.*s+withins+([0-9]+)s+errors;.*/1/p')
. I'm pretty sure,this can be done using onesed
orawk
.
– User123
Mar 25 at 9:43
What I get after this is the following. Is there a way to extract only the second number? : agrep: 4 words match within 2 errors; search for them? (y/n) agrep: 1 word matches within 1 error; search for it? (y/n) agrep: 2 words match within 4 errors; search for them? (y/n) agrep: 1 word matches within 2 errors; search for it? (y/n)
– Victoria
Mar 25 at 10:02
add a comment |
What I am trying to do is to get the best-matching word in a file and the number of errors for it using agrep
. For now I am only able to get the word using this script:
array=(bla1 bla2 bla3)
for eachWord in "$array[@]"; do
result=$(yes "yes" | agrep -B $eachWord /home/victoria/file.txt)
printf "$resultn"
done
Where bla1,2,3 are some words.
The output I have is the following:
agrep: 4 words match within 2 errors; search for them? (y/n)counting
first
and
should
agrep: 1 word matches within 1 error; search for it? (y/n)should
agrep: 2 words match within 4 errors; search for them? (y/n)must
must
agrep: 1 word matches within 2 errors; search for it? (y/n)should
Is there any way I can have the number of errors (2,1,4,2 in the output example above)?
linux bash shell grep agrep
What I am trying to do is to get the best-matching word in a file and the number of errors for it using agrep
. For now I am only able to get the word using this script:
array=(bla1 bla2 bla3)
for eachWord in "$array[@]"; do
result=$(yes "yes" | agrep -B $eachWord /home/victoria/file.txt)
printf "$resultn"
done
Where bla1,2,3 are some words.
The output I have is the following:
agrep: 4 words match within 2 errors; search for them? (y/n)counting
first
and
should
agrep: 1 word matches within 1 error; search for it? (y/n)should
agrep: 2 words match within 4 errors; search for them? (y/n)must
must
agrep: 1 word matches within 2 errors; search for it? (y/n)should
Is there any way I can have the number of errors (2,1,4,2 in the output example above)?
linux bash shell grep agrep
linux bash shell grep agrep
edited Mar 25 at 12:16
agc
5,2091539
5,2091539
asked Mar 25 at 8:34
VictoriaVictoria
49118
49118
What do you want with it?
– Inian
Mar 25 at 8:58
the Levenstein distance for mine and the best-matching word
– Victoria
Mar 25 at 9:24
1
As far as i've understood, you want the output to be: 2 1 4 2(i.e, number of errors). Can you try this:result=$(yes "yes" | agrep -B $eachWord /home/victoria/file.txt|sed -E -n 's/.*s+withins+([0-9]+)s+errors;.*/1/p')
. I'm pretty sure,this can be done using onesed
orawk
.
– User123
Mar 25 at 9:43
What I get after this is the following. Is there a way to extract only the second number? : agrep: 4 words match within 2 errors; search for them? (y/n) agrep: 1 word matches within 1 error; search for it? (y/n) agrep: 2 words match within 4 errors; search for them? (y/n) agrep: 1 word matches within 2 errors; search for it? (y/n)
– Victoria
Mar 25 at 10:02
add a comment |
What do you want with it?
– Inian
Mar 25 at 8:58
the Levenstein distance for mine and the best-matching word
– Victoria
Mar 25 at 9:24
1
As far as i've understood, you want the output to be: 2 1 4 2(i.e, number of errors). Can you try this:result=$(yes "yes" | agrep -B $eachWord /home/victoria/file.txt|sed -E -n 's/.*s+withins+([0-9]+)s+errors;.*/1/p')
. I'm pretty sure,this can be done using onesed
orawk
.
– User123
Mar 25 at 9:43
What I get after this is the following. Is there a way to extract only the second number? : agrep: 4 words match within 2 errors; search for them? (y/n) agrep: 1 word matches within 1 error; search for it? (y/n) agrep: 2 words match within 4 errors; search for them? (y/n) agrep: 1 word matches within 2 errors; search for it? (y/n)
– Victoria
Mar 25 at 10:02
What do you want with it?
– Inian
Mar 25 at 8:58
What do you want with it?
– Inian
Mar 25 at 8:58
the Levenstein distance for mine and the best-matching word
– Victoria
Mar 25 at 9:24
the Levenstein distance for mine and the best-matching word
– Victoria
Mar 25 at 9:24
1
1
As far as i've understood, you want the output to be: 2 1 4 2(i.e, number of errors). Can you try this:
result=$(yes "yes" | agrep -B $eachWord /home/victoria/file.txt|sed -E -n 's/.*s+withins+([0-9]+)s+errors;.*/1/p')
. I'm pretty sure,this can be done using one sed
or awk
.– User123
Mar 25 at 9:43
As far as i've understood, you want the output to be: 2 1 4 2(i.e, number of errors). Can you try this:
result=$(yes "yes" | agrep -B $eachWord /home/victoria/file.txt|sed -E -n 's/.*s+withins+([0-9]+)s+errors;.*/1/p')
. I'm pretty sure,this can be done using one sed
or awk
.– User123
Mar 25 at 9:43
What I get after this is the following. Is there a way to extract only the second number? : agrep: 4 words match within 2 errors; search for them? (y/n) agrep: 1 word matches within 1 error; search for it? (y/n) agrep: 2 words match within 4 errors; search for them? (y/n) agrep: 1 word matches within 2 errors; search for it? (y/n)
– Victoria
Mar 25 at 10:02
What I get after this is the following. Is there a way to extract only the second number? : agrep: 4 words match within 2 errors; search for them? (y/n) agrep: 1 word matches within 1 error; search for it? (y/n) agrep: 2 words match within 4 errors; search for them? (y/n) agrep: 1 word matches within 2 errors; search for it? (y/n)
– Victoria
Mar 25 at 10:02
add a comment |
1 Answer
1
active
oldest
votes
The main problem is, that agrep
reports the errors to standard error (file descriptor 2) and not to standard out (file descriptor 1). In order to throw away stdout and return stderr, you have to redirect stdout to /dev/null and redirect stderr to stdout:
2>&1 1>/dev/null
The minor problem is, that agrep
does not output proper line endings, if you feed it by yes
. You have to write a newline it stderr:
echo >&2
Finally, as User123 told you, you need a sed
command to extract the number of errors.
This is an example:
for a in r1234t rot ruht rood; do
yes y | agrep -B "$a" /etc/passwd
echo >&2
done 2>&1 1>/dev/null |
sed -n 's/.* ([0-9]+) error.*/1/p'
Output is:
4
1
2
1
I guess the OP only wants the second number (i.e more precisely, the number of errors: the number before the string 'errorrs'), sosed
command could be modified a bit:'s/.*s+withins+([0-9]+)s+errors;.*/1/p'
– User123
Mar 26 at 5:30
add a comment |
Your Answer
StackExchange.ifUsing("editor", function ()
StackExchange.using("externalEditor", function ()
StackExchange.using("snippets", function ()
StackExchange.snippets.init();
);
);
, "code-snippets");
StackExchange.ready(function()
var channelOptions =
tags: "".split(" "),
id: "1"
;
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%2fstackoverflow.com%2fquestions%2f55333850%2fshell-display-number-of-errors-for-best-matches-in-agrep%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
The main problem is, that agrep
reports the errors to standard error (file descriptor 2) and not to standard out (file descriptor 1). In order to throw away stdout and return stderr, you have to redirect stdout to /dev/null and redirect stderr to stdout:
2>&1 1>/dev/null
The minor problem is, that agrep
does not output proper line endings, if you feed it by yes
. You have to write a newline it stderr:
echo >&2
Finally, as User123 told you, you need a sed
command to extract the number of errors.
This is an example:
for a in r1234t rot ruht rood; do
yes y | agrep -B "$a" /etc/passwd
echo >&2
done 2>&1 1>/dev/null |
sed -n 's/.* ([0-9]+) error.*/1/p'
Output is:
4
1
2
1
I guess the OP only wants the second number (i.e more precisely, the number of errors: the number before the string 'errorrs'), sosed
command could be modified a bit:'s/.*s+withins+([0-9]+)s+errors;.*/1/p'
– User123
Mar 26 at 5:30
add a comment |
The main problem is, that agrep
reports the errors to standard error (file descriptor 2) and not to standard out (file descriptor 1). In order to throw away stdout and return stderr, you have to redirect stdout to /dev/null and redirect stderr to stdout:
2>&1 1>/dev/null
The minor problem is, that agrep
does not output proper line endings, if you feed it by yes
. You have to write a newline it stderr:
echo >&2
Finally, as User123 told you, you need a sed
command to extract the number of errors.
This is an example:
for a in r1234t rot ruht rood; do
yes y | agrep -B "$a" /etc/passwd
echo >&2
done 2>&1 1>/dev/null |
sed -n 's/.* ([0-9]+) error.*/1/p'
Output is:
4
1
2
1
I guess the OP only wants the second number (i.e more precisely, the number of errors: the number before the string 'errorrs'), sosed
command could be modified a bit:'s/.*s+withins+([0-9]+)s+errors;.*/1/p'
– User123
Mar 26 at 5:30
add a comment |
The main problem is, that agrep
reports the errors to standard error (file descriptor 2) and not to standard out (file descriptor 1). In order to throw away stdout and return stderr, you have to redirect stdout to /dev/null and redirect stderr to stdout:
2>&1 1>/dev/null
The minor problem is, that agrep
does not output proper line endings, if you feed it by yes
. You have to write a newline it stderr:
echo >&2
Finally, as User123 told you, you need a sed
command to extract the number of errors.
This is an example:
for a in r1234t rot ruht rood; do
yes y | agrep -B "$a" /etc/passwd
echo >&2
done 2>&1 1>/dev/null |
sed -n 's/.* ([0-9]+) error.*/1/p'
Output is:
4
1
2
1
The main problem is, that agrep
reports the errors to standard error (file descriptor 2) and not to standard out (file descriptor 1). In order to throw away stdout and return stderr, you have to redirect stdout to /dev/null and redirect stderr to stdout:
2>&1 1>/dev/null
The minor problem is, that agrep
does not output proper line endings, if you feed it by yes
. You have to write a newline it stderr:
echo >&2
Finally, as User123 told you, you need a sed
command to extract the number of errors.
This is an example:
for a in r1234t rot ruht rood; do
yes y | agrep -B "$a" /etc/passwd
echo >&2
done 2>&1 1>/dev/null |
sed -n 's/.* ([0-9]+) error.*/1/p'
Output is:
4
1
2
1
answered Mar 25 at 13:10
cevingceving
10.8k360108
10.8k360108
I guess the OP only wants the second number (i.e more precisely, the number of errors: the number before the string 'errorrs'), sosed
command could be modified a bit:'s/.*s+withins+([0-9]+)s+errors;.*/1/p'
– User123
Mar 26 at 5:30
add a comment |
I guess the OP only wants the second number (i.e more precisely, the number of errors: the number before the string 'errorrs'), sosed
command could be modified a bit:'s/.*s+withins+([0-9]+)s+errors;.*/1/p'
– User123
Mar 26 at 5:30
I guess the OP only wants the second number (i.e more precisely, the number of errors: the number before the string 'errorrs'), so
sed
command could be modified a bit: 's/.*s+withins+([0-9]+)s+errors;.*/1/p'
– User123
Mar 26 at 5:30
I guess the OP only wants the second number (i.e more precisely, the number of errors: the number before the string 'errorrs'), so
sed
command could be modified a bit: 's/.*s+withins+([0-9]+)s+errors;.*/1/p'
– User123
Mar 26 at 5:30
add a comment |
Thanks for contributing an answer to Stack Overflow!
- 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%2fstackoverflow.com%2fquestions%2f55333850%2fshell-display-number-of-errors-for-best-matches-in-agrep%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
What do you want with it?
– Inian
Mar 25 at 8:58
the Levenstein distance for mine and the best-matching word
– Victoria
Mar 25 at 9:24
1
As far as i've understood, you want the output to be: 2 1 4 2(i.e, number of errors). Can you try this:
result=$(yes "yes" | agrep -B $eachWord /home/victoria/file.txt|sed -E -n 's/.*s+withins+([0-9]+)s+errors;.*/1/p')
. I'm pretty sure,this can be done using onesed
orawk
.– User123
Mar 25 at 9:43
What I get after this is the following. Is there a way to extract only the second number? : agrep: 4 words match within 2 errors; search for them? (y/n) agrep: 1 word matches within 1 error; search for it? (y/n) agrep: 2 words match within 4 errors; search for them? (y/n) agrep: 1 word matches within 2 errors; search for it? (y/n)
– Victoria
Mar 25 at 10:02