<div dir="ltr"><div><div>I get it!<br><br></div> cat x | grep y<br></div><br>is redundant. did I learn that when it wasn't redundant? if it never has been redundant I wonder why I thought the pipe was needed?<br></div>
<div class="gmail_extra"><br clear="all"><div>:-)~MIKE~(-:</div>
<br><br><div class="gmail_quote">On Mon, Aug 25, 2014 at 4:25 PM, Brian Cluff <span dir="ltr"><<a href="mailto:brian@snaptek.com" target="_blank">brian@snaptek.com</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
You'll need to add some single quotes to keep the shell from interpreting your regex as shell code like this:<br>
<br>
grep -E 'error|fail' {make,install,check}.fail<br>
<br>
Without the single quotes you are telling the system to cat from your set of files and look for lines with the word error and pipe that to a program called fail.<br>
<br>
I found that I did have to add the -E even thought the man page says that in the GNU version of grep the basic and extended regular expressions are the same... it appears that is not the case in practice.<br>
<br>
Brian Cluff<div class=""><br>
<br>
On 08/25/2014 12:56 PM, Michael Havens wrote:<br>
</div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div class="">
I have 3 files, make.fail, install.fail, and check.fail. I want to check<br>
for two words in those files: error and fail.<br>
<br>
would this work?<br>
<br>
cat {make,install,check}.fail | grep -i error|fail<br>
<br>
I was told to put the 'E' option in to grep. Looking at the man page it<br>
seems that the E option is only useful if I were greping for something<br>
that begins with a '{'. AM I misreading the man page?<br>
<br>
man quote:<br>
GNU grep -E attempts to support traditional usage by assuming<br>
that { is<br>
not special if it would be the start of an invalid<br>
interval<br>
specification. For example, the command grep -E '{1' searches<br>
for the<br>
two-character string {1 instead of reporting a syntax error<br>
in the<br>
regular expression. POSIX allows this behavior as an<br>
extension, but<br>
portable scripts should avoid it.<br>
<br>
<br>
<br>
:-)~MIKE~(-:<br>
<br>
<br>
On Mon, Aug 25, 2014 at 12:24 PM, Michael Havens <<a href="mailto:bmike1@gmail.com" target="_blank">bmike1@gmail.com</a><br></div><div class="">
<mailto:<a href="mailto:bmike1@gmail.com" target="_blank">bmike1@gmail.com</a>>> wrote:<br>
<br>
you guys are so helpful! Thanks.<br>
<br>
:-)~MIKE~(-:<br>
<br>
<br>
On Sun, Aug 24, 2014 at 7:40 PM, Jon Kettenhofen <<a href="mailto:subs@kexsof.com" target="_blank">subs@kexsof.com</a><br></div><div><div class="h5">
<mailto:<a href="mailto:subs@kexsof.com" target="_blank">subs@kexsof.com</a>>> wrote:<br>
<br>
I like visible proofs, so here's a test I ran:<br>
(terminal output was as is shown)<br>
<br>
[jon@localhost ~]$ rm temp<br>
[jon@localhost ~]$ echo >>temp<br>
[jon@localhost ~]$ echo $?<br>
0<br>
[jon@localhost ~]$ cat temp<br>
<br>
[jon@localhost ~]$ echo >>temp 2>&1<br>
[jon@localhost ~]$ echo $?<br>
0<br>
[jon@localhost ~]$ cat temp<br>
<br>
<br>
[jon@localhost ~]$<br>
<br>
as you can see, no errors and the single ">" did not erase the<br>
file when used in this manner. So Mike's script should work as<br>
intended<br>
at least if there is no stderr output.<br>
<br>
but suppose there was an error? (apologizing for the length of ...)<br>
<br>
[jon@localhost ~]$ echo "echo" >test<br>
[jon@localhost ~]$ echo "ls temp2" >>test<br>
[jon@localhost ~]$ # test ls of non-existent file<br>
[jon@localhost ~]$ ls temp2<br>
ls: cannot access temp2: No such file or directory<br>
[jon@localhost ~]$ echo $?<br>
2<br>
[jon@localhost ~]$ # see, we get both an error and stderr message<br>
[jon@localhost ~]$ # so<br>
[jon@localhost ~]$ mv test test.sh<br>
[jon@localhost ~]$ chgmod +x test.sh<br>
bash: chgmod: command not found...<br>
[jon@localhost ~]$ chmod +x test.sh<br>
[jon@localhost ~]$ # i'm not perfect!<br>
[jon@localhost ~]$ rm temp<br>
[jon@localhost ~]$ ./test.sh >>temp<br>
ls: cannot access temp2: No such file or directory<br>
[jon@localhost ~]$ echo $?<br>
2<br>
[jon@localhost ~]$ cat temp<br>
<br>
[jon@localhost ~]$ ./test.sh >>temp 2>&1<br>
[jon@localhost ~]$ echo $?<br>
2<br>
[jon@localhost ~]$ cat temp<br>
<br>
<br>
ls: cannot access temp2: No such file or directory<br>
[jon@localhost ~]$<br>
<br>
as you can see, Mike's script will work as he apparently intended,<br>
providing he's using a modern version of bash.<br>
<br>
<br>
<br>
On 08/24/2014 09:56 PM, James Mcphee wrote:<br>
<br>
you've said make, append stdout (default file descriptor 1)<br>
to file<br>
make.fail, assign stderr (default filedescriptor 2) the same<br>
filedescriptor as stdout. So... If the intent was to have<br>
both stderr<br>
and stdout append make.fail, then it is correct.<br>
<br>
<br>
On Sun, Aug 24, 2014 at 6:06 PM, Michael Havens<br>
<<a href="mailto:bmike1@gmail.com" target="_blank">bmike1@gmail.com</a> <mailto:<a href="mailto:bmike1@gmail.com" target="_blank">bmike1@gmail.com</a>><br></div></div><div class="">
<mailto:<a href="mailto:bmike1@gmail.com" target="_blank">bmike1@gmail.com</a> <mailto:<a href="mailto:bmike1@gmail.com" target="_blank">bmike1@gmail.com</a>>>> wrote:<br>
<br>
what I really need to know is will this:<br>
<br>
make>>make.fail 2>&1<br>
<br>
send stderr and stdout to the file 'make.fail' or did I<br>
write it<br>
incorrectly?<br>
<br>
:-)~MIKE~(-:<br>
<br>
<br>
On Sun, Aug 24, 2014 at 2:56 PM, Brian Cluff<br>
<<a href="mailto:brian@snaptek.com" target="_blank">brian@snaptek.com</a> <mailto:<a href="mailto:brian@snaptek.com" target="_blank">brian@snaptek.com</a>><br></div>
<mailto:<a href="mailto:brian@snaptek.com" target="_blank">brian@snaptek.com</a> <mailto:<a href="mailto:brian@snaptek.com" target="_blank">brian@snaptek.com</a>>>><div><div class="h5"><br>
wrote:<br>
<br>
the > will delete any file that it points at even<br>
if the command<br>
doesn't actually output anything. It will even<br>
delete the file<br>
is the command doesn't exist like if you type grep<br>
as gerp<br>
>file, file will still be created/overwritten.<br>
<br>
If you want to make sure that your command doesn't<br>
overwrite any<br>
existing files you have to set the noclobber option<br>
like:<br>
$ set -o noclobber<br>
<br>
A good trick to know:<br>
You can use the > to delete the contents of a file<br>
without<br>
having to delete and recreate the file by simply<br>
doing this:<br>
$ >yourfile<br>
<br>
Brian Cluff<br>
<br>
<br>
On 08/24/2014 02:36 PM, Michael Havens wrote:<br>
<br>
I have a question about redirections:<br>
<br>
make>>make.fail 2>&1<br>
<br>
tells it make and then to send (>) stderr (2)<br>
to stdout (1)<br>
and also to<br>
send stdout that way also (&1). finally all of<br>
that gets<br>
sent to a file<br>
named make.fail (>>). Isn't '>>' actually<br>
'append' whereas<br>
'>' would<br>
work just as well so long as the file didn't<br>
already exist?<br>
If the file<br>
did exist would I get an error or would the<br>
file be overwritten?<br>
:-)~MIKE~(-:<br>
<br>
<br>
<br></div></div>
------------------------------<u></u>____---------------------<br>
PLUG-discuss mailing list -<br>
PLUG-discuss@lists.phxlinux.__<u></u>__org<br>
<mailto:<a href="mailto:PLUG-discuss@lists." target="_blank">PLUG-discuss@lists.</a>__<a href="http://phxlinux.org" target="_blank">p<u></u>hxlinux.org</a><div class=""><br>
<mailto:<a href="mailto:PLUG-discuss@lists.phxlinux.org" target="_blank">PLUG-discuss@lists.<u></u>phxlinux.org</a>>><br>
<br>
To subscribe, unsubscribe, or to change your<br>
mail settings:<br></div>
<a href="http://lists.phxlinux.org/____mailman/listinfo/plug-discuss" target="_blank">http://lists.phxlinux.org/____<u></u>mailman/listinfo/plug-discuss</a><br>
<<a href="http://lists.phxlinux.org/__mailman/listinfo/plug-discuss" target="_blank">http://lists.phxlinux.org/__<u></u>mailman/listinfo/plug-discuss</a>><br>
<br>
<<a href="http://lists.phxlinux.org/__mailman/listinfo/plug-discuss" target="_blank">http://lists.phxlinux.org/__<u></u>mailman/listinfo/plug-discuss</a><br>
<<a href="http://lists.phxlinux.org/mailman/listinfo/plug-discuss" target="_blank">http://lists.phxlinux.org/<u></u>mailman/listinfo/plug-discuss</a>><u></u>><br>
<br>
------------------------------<u></u>____---------------------<br>
PLUG-discuss mailing list -<br>
PLUG-discuss@lists.phxlinux.__<u></u>__org<br>
<mailto:<a href="mailto:PLUG-discuss@lists." target="_blank">PLUG-discuss@lists.</a>__<a href="http://phxlinux.org" target="_blank">p<u></u>hxlinux.org</a><div class=""><br>
<mailto:<a href="mailto:PLUG-discuss@lists.phxlinux.org" target="_blank">PLUG-discuss@lists.<u></u>phxlinux.org</a>>><br>
<br>
To subscribe, unsubscribe, or to change your mail<br>
settings:<br></div>
<a href="http://lists.phxlinux.org/____mailman/listinfo/plug-discuss" target="_blank">http://lists.phxlinux.org/____<u></u>mailman/listinfo/plug-discuss</a><br>
<<a href="http://lists.phxlinux.org/__mailman/listinfo/plug-discuss" target="_blank">http://lists.phxlinux.org/__<u></u>mailman/listinfo/plug-discuss</a>><div class=""><br>
<br>
<br>
<<a href="http://lists.phxlinux.org/__mailman/listinfo/plug-discuss" target="_blank">http://lists.phxlinux.org/__<u></u>mailman/listinfo/plug-discuss</a><br>
<<a href="http://lists.phxlinux.org/mailman/listinfo/plug-discuss" target="_blank">http://lists.phxlinux.org/<u></u>mailman/listinfo/plug-discuss</a>><u></u>><br>
<br>
<br>
<br>
------------------------------<u></u>__---------------------<br>
PLUG-discuss mailing list -<br>
PLUG-discuss@lists.phxlinux.__<u></u>org<br>
<mailto:<a href="mailto:PLUG-discuss@lists.phxlinux.org" target="_blank">PLUG-discuss@lists.<u></u>phxlinux.org</a>><br></div>
<mailto:<a href="mailto:PLUG-discuss@lists." target="_blank">PLUG-discuss@lists.</a>__<a href="http://phxlinux.org" target="_blank">p<u></u>hxlinux.org</a><div class=""><br>
<mailto:<a href="mailto:PLUG-discuss@lists.phxlinux.org" target="_blank">PLUG-discuss@lists.<u></u>phxlinux.org</a>>><br>
<br>
To subscribe, unsubscribe, or to change your mail settings:<br>
<a href="http://lists.phxlinux.org/__mailman/listinfo/plug-discuss" target="_blank">http://lists.phxlinux.org/__<u></u>mailman/listinfo/plug-discuss</a><br>
<<a href="http://lists.phxlinux.org/mailman/listinfo/plug-discuss" target="_blank">http://lists.phxlinux.org/<u></u>mailman/listinfo/plug-discuss</a>><br>
<br>
<br>
<br>
<br></div><div class="">
--<br>
James McPhee<br>
<a href="mailto:jmcphe@gmail.com" target="_blank">jmcphe@gmail.com</a> <mailto:<a href="mailto:jmcphe@gmail.com" target="_blank">jmcphe@gmail.com</a>><br></div>
<mailto:<a href="mailto:jmcphe@gmail.com" target="_blank">jmcphe@gmail.com</a> <mailto:<a href="mailto:jmcphe@gmail.com" target="_blank">jmcphe@gmail.com</a>>><div class=""><br>
<br>
<br>
<br>
------------------------------<u></u>__---------------------<br>
PLUG-discuss mailing list -<br>
PLUG-discuss@lists.phxlinux.__<u></u>org<br>
<mailto:<a href="mailto:PLUG-discuss@lists.phxlinux.org" target="_blank">PLUG-discuss@lists.<u></u>phxlinux.org</a>><br>
To subscribe, unsubscribe, or to change your mail settings:<br>
<a href="http://lists.phxlinux.org/__mailman/listinfo/plug-discuss" target="_blank">http://lists.phxlinux.org/__<u></u>mailman/listinfo/plug-discuss</a><br>
<<a href="http://lists.phxlinux.org/mailman/listinfo/plug-discuss" target="_blank">http://lists.phxlinux.org/<u></u>mailman/listinfo/plug-discuss</a>><br>
<br>
<br>
------------------------------<u></u>__---------------------<br>
PLUG-discuss mailing list - PLUG-discuss@lists.phxlinux.__<u></u>org<br>
<mailto:<a href="mailto:PLUG-discuss@lists.phxlinux.org" target="_blank">PLUG-discuss@lists.<u></u>phxlinux.org</a>><br>
To subscribe, unsubscribe, or to change your mail settings:<br>
<a href="http://lists.phxlinux.org/__mailman/listinfo/plug-discuss" target="_blank">http://lists.phxlinux.org/__<u></u>mailman/listinfo/plug-discuss</a><br>
<<a href="http://lists.phxlinux.org/mailman/listinfo/plug-discuss" target="_blank">http://lists.phxlinux.org/<u></u>mailman/listinfo/plug-discuss</a>><br>
<br>
<br>
<br>
<br>
<br>
------------------------------<u></u>---------------------<br>
PLUG-discuss mailing list - <a href="mailto:PLUG-discuss@lists.phxlinux.org" target="_blank">PLUG-discuss@lists.phxlinux.<u></u>org</a><br></div><div class="">
To subscribe, unsubscribe, or to change your mail settings:<br>
<a href="http://lists.phxlinux.org/mailman/listinfo/plug-discuss" target="_blank">http://lists.phxlinux.org/<u></u>mailman/listinfo/plug-discuss</a><br>
<br>
</div></blockquote><div class="HOEnZb"><div class="h5">
<br>
------------------------------<u></u>---------------------<br>
PLUG-discuss mailing list - <a href="mailto:PLUG-discuss@lists.phxlinux.org" target="_blank">PLUG-discuss@lists.phxlinux.<u></u>org</a><br>
To subscribe, unsubscribe, or to change your mail settings:<br>
<a href="http://lists.phxlinux.org/mailman/listinfo/plug-discuss" target="_blank">http://lists.phxlinux.org/<u></u>mailman/listinfo/plug-discuss</a><br>
</div></div></blockquote></div><br></div>