Different output when aliasWhy do I get “Binary file matches” with grep -I?Does one alias affect another...

Different output when alias

How long can a 35mm film be used/stored before it starts to lose its quality after expiry?

Unidentified items in bicycle tube repair kit

Password expiration with Password manager

Is thermodynamics only applicable to systems in equilibrium?

What happens if I start too many background jobs?

What are the spoon bit of a spoon and fork bit of a fork called?

What does air vanishing on contact sound like?

Can fracking help reduce CO2?

Floor tile layout process?

When do aircrafts become solarcrafts?

Selecting a secure PIN for building access

Loading but not using TikZ changes a file

Pigeonhole Principle Problem

If 1. e4 c6 is considered as a sound defense for black, why is 1. c3 so rare?

Why do money exchangers give different rates to different bills

Declining welcome lunch invitation at new job due to Ramadan

Stark VS Thanos

Why are notes ordered like they are on a piano?

How to assert on pagereference where the endpoint of pagereference is predefined

Hang 20lb projector screen on hardieplank

How did Captain America use this power?

How do I tell my manager that his code review comment is wrong?

CRT Oscilloscope - part of the plot is missing



Different output when alias


Why do I get “Binary file matches” with grep -I?Does one alias affect another alias?Merge two lists while removing duplicatesgrep alias to safely ignore multiple directoriesSpecial characters in alias~/.bash_aliases vs alias commandWhy alias behave different than running bash command directly?Bash alias problemAlias grep quote usageRedirection and piping for greppingRefresh command output in alias






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







5















I have a command set as an alias like this:



alias badalarm="cat ~/sagLogs/* | grep -I 'failed to generate expected' | awk '{print $4}' | sort | uniq | tee /dev/tty | wc -l" 


It gives me this output:



$ badalarm
alg-t1sg0103
alg-t1sg0104
all-t1sg0006
all-t1sg0009
input)
5


However, if I run the commands from the CLI directly I get:



$ cat ~/sagLogs/* | grep -I 'failed to generate expected' | awk '{print $4}' | sort | uniq | tee /dev/tty | wc -l
alg-t1sg0103
alg-t1sg0104
all-t1sg0006
all-t1sg0009
4


How come the alias version is picking up some other file? When I use
cat ~/sagLogs/* | grep 'failed to generate expected'



I get this output:



[...]
Apr:09:09:31:01: >>>1 on all-t1sg0009 failed to generate expected 134
Apr:09:09:31:01: >>>2 on all-t1sg0009 failed to generate expected 107
Apr:09:09:31:01: >>>2 on all-t1sg0009 failed to generate expected 108
Apr:10:08:00:35: >>>1 on all-t1sg0009 failed to generate expected 133
Apr:10:08:00:35: >>>1 on all-t1sg0009 failed to generate expected 107
Binary file (standard input) matches


How can I omit the 'standard input' file from my alias?










share|improve this question

























  • Are you sure you want to omit it? it likely indicates a genuine match in an encoded file - see Why do I get “Binary file matches” with grep -I?

    – steeldriver
    6 hours ago











  • @steeldriver I'm not well versed with what sort of scenarios might create this binary file. My intentions are for this directory to contain nothing but my logs (names like xyz-t1sg00123) and see if they recently have the 'failed to generate' message. These logs are generated in a script which is appending the file via an echo command. I dont think that this would result in the creation of an encoded file, so I think it's safe to omit. Let me know what you think. Thanks.

    – KuboMD
    6 hours ago


















5















I have a command set as an alias like this:



alias badalarm="cat ~/sagLogs/* | grep -I 'failed to generate expected' | awk '{print $4}' | sort | uniq | tee /dev/tty | wc -l" 


It gives me this output:



$ badalarm
alg-t1sg0103
alg-t1sg0104
all-t1sg0006
all-t1sg0009
input)
5


However, if I run the commands from the CLI directly I get:



$ cat ~/sagLogs/* | grep -I 'failed to generate expected' | awk '{print $4}' | sort | uniq | tee /dev/tty | wc -l
alg-t1sg0103
alg-t1sg0104
all-t1sg0006
all-t1sg0009
4


How come the alias version is picking up some other file? When I use
cat ~/sagLogs/* | grep 'failed to generate expected'



I get this output:



[...]
Apr:09:09:31:01: >>>1 on all-t1sg0009 failed to generate expected 134
Apr:09:09:31:01: >>>2 on all-t1sg0009 failed to generate expected 107
Apr:09:09:31:01: >>>2 on all-t1sg0009 failed to generate expected 108
Apr:10:08:00:35: >>>1 on all-t1sg0009 failed to generate expected 133
Apr:10:08:00:35: >>>1 on all-t1sg0009 failed to generate expected 107
Binary file (standard input) matches


How can I omit the 'standard input' file from my alias?










share|improve this question

























  • Are you sure you want to omit it? it likely indicates a genuine match in an encoded file - see Why do I get “Binary file matches” with grep -I?

    – steeldriver
    6 hours ago











  • @steeldriver I'm not well versed with what sort of scenarios might create this binary file. My intentions are for this directory to contain nothing but my logs (names like xyz-t1sg00123) and see if they recently have the 'failed to generate' message. These logs are generated in a script which is appending the file via an echo command. I dont think that this would result in the creation of an encoded file, so I think it's safe to omit. Let me know what you think. Thanks.

    – KuboMD
    6 hours ago














5












5








5








I have a command set as an alias like this:



alias badalarm="cat ~/sagLogs/* | grep -I 'failed to generate expected' | awk '{print $4}' | sort | uniq | tee /dev/tty | wc -l" 


It gives me this output:



$ badalarm
alg-t1sg0103
alg-t1sg0104
all-t1sg0006
all-t1sg0009
input)
5


However, if I run the commands from the CLI directly I get:



$ cat ~/sagLogs/* | grep -I 'failed to generate expected' | awk '{print $4}' | sort | uniq | tee /dev/tty | wc -l
alg-t1sg0103
alg-t1sg0104
all-t1sg0006
all-t1sg0009
4


How come the alias version is picking up some other file? When I use
cat ~/sagLogs/* | grep 'failed to generate expected'



I get this output:



[...]
Apr:09:09:31:01: >>>1 on all-t1sg0009 failed to generate expected 134
Apr:09:09:31:01: >>>2 on all-t1sg0009 failed to generate expected 107
Apr:09:09:31:01: >>>2 on all-t1sg0009 failed to generate expected 108
Apr:10:08:00:35: >>>1 on all-t1sg0009 failed to generate expected 133
Apr:10:08:00:35: >>>1 on all-t1sg0009 failed to generate expected 107
Binary file (standard input) matches


How can I omit the 'standard input' file from my alias?










share|improve this question
















I have a command set as an alias like this:



alias badalarm="cat ~/sagLogs/* | grep -I 'failed to generate expected' | awk '{print $4}' | sort | uniq | tee /dev/tty | wc -l" 


It gives me this output:



$ badalarm
alg-t1sg0103
alg-t1sg0104
all-t1sg0006
all-t1sg0009
input)
5


However, if I run the commands from the CLI directly I get:



$ cat ~/sagLogs/* | grep -I 'failed to generate expected' | awk '{print $4}' | sort | uniq | tee /dev/tty | wc -l
alg-t1sg0103
alg-t1sg0104
all-t1sg0006
all-t1sg0009
4


How come the alias version is picking up some other file? When I use
cat ~/sagLogs/* | grep 'failed to generate expected'



I get this output:



[...]
Apr:09:09:31:01: >>>1 on all-t1sg0009 failed to generate expected 134
Apr:09:09:31:01: >>>2 on all-t1sg0009 failed to generate expected 107
Apr:09:09:31:01: >>>2 on all-t1sg0009 failed to generate expected 108
Apr:10:08:00:35: >>>1 on all-t1sg0009 failed to generate expected 133
Apr:10:08:00:35: >>>1 on all-t1sg0009 failed to generate expected 107
Binary file (standard input) matches


How can I omit the 'standard input' file from my alias?







bash grep alias






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited 7 hours ago









Rui F Ribeiro

42.5k1485146




42.5k1485146










asked 7 hours ago









KuboMDKuboMD

1888




1888













  • Are you sure you want to omit it? it likely indicates a genuine match in an encoded file - see Why do I get “Binary file matches” with grep -I?

    – steeldriver
    6 hours ago











  • @steeldriver I'm not well versed with what sort of scenarios might create this binary file. My intentions are for this directory to contain nothing but my logs (names like xyz-t1sg00123) and see if they recently have the 'failed to generate' message. These logs are generated in a script which is appending the file via an echo command. I dont think that this would result in the creation of an encoded file, so I think it's safe to omit. Let me know what you think. Thanks.

    – KuboMD
    6 hours ago



















  • Are you sure you want to omit it? it likely indicates a genuine match in an encoded file - see Why do I get “Binary file matches” with grep -I?

    – steeldriver
    6 hours ago











  • @steeldriver I'm not well versed with what sort of scenarios might create this binary file. My intentions are for this directory to contain nothing but my logs (names like xyz-t1sg00123) and see if they recently have the 'failed to generate' message. These logs are generated in a script which is appending the file via an echo command. I dont think that this would result in the creation of an encoded file, so I think it's safe to omit. Let me know what you think. Thanks.

    – KuboMD
    6 hours ago

















Are you sure you want to omit it? it likely indicates a genuine match in an encoded file - see Why do I get “Binary file matches” with grep -I?

– steeldriver
6 hours ago





Are you sure you want to omit it? it likely indicates a genuine match in an encoded file - see Why do I get “Binary file matches” with grep -I?

– steeldriver
6 hours ago













@steeldriver I'm not well versed with what sort of scenarios might create this binary file. My intentions are for this directory to contain nothing but my logs (names like xyz-t1sg00123) and see if they recently have the 'failed to generate' message. These logs are generated in a script which is appending the file via an echo command. I dont think that this would result in the creation of an encoded file, so I think it's safe to omit. Let me know what you think. Thanks.

– KuboMD
6 hours ago





@steeldriver I'm not well versed with what sort of scenarios might create this binary file. My intentions are for this directory to contain nothing but my logs (names like xyz-t1sg00123) and see if they recently have the 'failed to generate' message. These logs are generated in a script which is appending the file via an echo command. I dont think that this would result in the creation of an encoded file, so I think it's safe to omit. Let me know what you think. Thanks.

– KuboMD
6 hours ago










1 Answer
1






active

oldest

votes


















8














When you declare your alias, the $4 in the awk command is within double quotes (since the whole alias string is within double quotes). This means that it will be expanded by the shell, most likely to an empty string. It does not matter that the $4 is within single quotes within the double quotes.



Instead, consider using a shell function,



badalarm () {
cat "$HOME"/sagLogs/* |
grep -I 'failed to generate expected' |
awk '{ print $4 }' | sort -u |
tee | wc -l
}


This avoids any quoting issues.



I also shorten the pipeline somewhat and replaced outputting directly to the TTY with outputting to standard output instead (so that both the output of tee and wc -l are sent there).






share|improve this answer


























  • Related: Parameter expansion (variable expansion) and quotes within quotes.

    – Kamil Maciorowski
    5 hours ago











  • Awesome! Thank you.

    – KuboMD
    5 hours ago











  • Alternatively, you could change to awk '{print $4}' in your alias. This will quote the $ while defining the alias, allowing the intended interpretation when the alias is actually issued.

    – Paul Sinclair
    2 hours ago












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%2f516172%2fdifferent-output-when-alias%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









8














When you declare your alias, the $4 in the awk command is within double quotes (since the whole alias string is within double quotes). This means that it will be expanded by the shell, most likely to an empty string. It does not matter that the $4 is within single quotes within the double quotes.



Instead, consider using a shell function,



badalarm () {
cat "$HOME"/sagLogs/* |
grep -I 'failed to generate expected' |
awk '{ print $4 }' | sort -u |
tee | wc -l
}


This avoids any quoting issues.



I also shorten the pipeline somewhat and replaced outputting directly to the TTY with outputting to standard output instead (so that both the output of tee and wc -l are sent there).






share|improve this answer


























  • Related: Parameter expansion (variable expansion) and quotes within quotes.

    – Kamil Maciorowski
    5 hours ago











  • Awesome! Thank you.

    – KuboMD
    5 hours ago











  • Alternatively, you could change to awk '{print $4}' in your alias. This will quote the $ while defining the alias, allowing the intended interpretation when the alias is actually issued.

    – Paul Sinclair
    2 hours ago
















8














When you declare your alias, the $4 in the awk command is within double quotes (since the whole alias string is within double quotes). This means that it will be expanded by the shell, most likely to an empty string. It does not matter that the $4 is within single quotes within the double quotes.



Instead, consider using a shell function,



badalarm () {
cat "$HOME"/sagLogs/* |
grep -I 'failed to generate expected' |
awk '{ print $4 }' | sort -u |
tee | wc -l
}


This avoids any quoting issues.



I also shorten the pipeline somewhat and replaced outputting directly to the TTY with outputting to standard output instead (so that both the output of tee and wc -l are sent there).






share|improve this answer


























  • Related: Parameter expansion (variable expansion) and quotes within quotes.

    – Kamil Maciorowski
    5 hours ago











  • Awesome! Thank you.

    – KuboMD
    5 hours ago











  • Alternatively, you could change to awk '{print $4}' in your alias. This will quote the $ while defining the alias, allowing the intended interpretation when the alias is actually issued.

    – Paul Sinclair
    2 hours ago














8












8








8







When you declare your alias, the $4 in the awk command is within double quotes (since the whole alias string is within double quotes). This means that it will be expanded by the shell, most likely to an empty string. It does not matter that the $4 is within single quotes within the double quotes.



Instead, consider using a shell function,



badalarm () {
cat "$HOME"/sagLogs/* |
grep -I 'failed to generate expected' |
awk '{ print $4 }' | sort -u |
tee | wc -l
}


This avoids any quoting issues.



I also shorten the pipeline somewhat and replaced outputting directly to the TTY with outputting to standard output instead (so that both the output of tee and wc -l are sent there).






share|improve this answer















When you declare your alias, the $4 in the awk command is within double quotes (since the whole alias string is within double quotes). This means that it will be expanded by the shell, most likely to an empty string. It does not matter that the $4 is within single quotes within the double quotes.



Instead, consider using a shell function,



badalarm () {
cat "$HOME"/sagLogs/* |
grep -I 'failed to generate expected' |
awk '{ print $4 }' | sort -u |
tee | wc -l
}


This avoids any quoting issues.



I also shorten the pipeline somewhat and replaced outputting directly to the TTY with outputting to standard output instead (so that both the output of tee and wc -l are sent there).







share|improve this answer














share|improve this answer



share|improve this answer








edited 5 hours ago

























answered 6 hours ago









KusalanandaKusalananda

144k18272450




144k18272450













  • Related: Parameter expansion (variable expansion) and quotes within quotes.

    – Kamil Maciorowski
    5 hours ago











  • Awesome! Thank you.

    – KuboMD
    5 hours ago











  • Alternatively, you could change to awk '{print $4}' in your alias. This will quote the $ while defining the alias, allowing the intended interpretation when the alias is actually issued.

    – Paul Sinclair
    2 hours ago



















  • Related: Parameter expansion (variable expansion) and quotes within quotes.

    – Kamil Maciorowski
    5 hours ago











  • Awesome! Thank you.

    – KuboMD
    5 hours ago











  • Alternatively, you could change to awk '{print $4}' in your alias. This will quote the $ while defining the alias, allowing the intended interpretation when the alias is actually issued.

    – Paul Sinclair
    2 hours ago

















Related: Parameter expansion (variable expansion) and quotes within quotes.

– Kamil Maciorowski
5 hours ago





Related: Parameter expansion (variable expansion) and quotes within quotes.

– Kamil Maciorowski
5 hours ago













Awesome! Thank you.

– KuboMD
5 hours ago





Awesome! Thank you.

– KuboMD
5 hours ago













Alternatively, you could change to awk '{print $4}' in your alias. This will quote the $ while defining the alias, allowing the intended interpretation when the alias is actually issued.

– Paul Sinclair
2 hours ago





Alternatively, you could change to awk '{print $4}' in your alias. This will quote the $ while defining the alias, allowing the intended interpretation when the alias is actually issued.

– Paul Sinclair
2 hours ago


















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%2f516172%2fdifferent-output-when-alias%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

Installing LyX: “No textclass is found.”LyX installation error- text class not found- 'Reconfigure' or...

(1602) Indiana Índice Designación y nombre Características orbitales Véase...

Universidad Autónoma de Occidente Índice Historia Campus Facultades Programas Académicos Medios de...