* How to run an awk command on file in emacs - using minGW on Windows
@ 2013-09-17 10:39 Angus Comber
2013-09-17 11:19 ` Eli Zaretskii
0 siblings, 1 reply; 8+ messages in thread
From: Angus Comber @ 2013-09-17 10:39 UTC (permalink / raw)
To: Emacs Help
If I am visiting a file in emacs I want to be able to run a simple awk
command, eg
awk /Sam/ test.txt
How would I construct this.
I tried:
m-! - to be able to run a shell cmd
awk '/Sam/' test.txt
But then I get this error:
awk: c:/MinGW/msys/1.0/Sam/ { print }
awk: ^ syntax error
awk: c:/MinGW/msys/1.0/Sam/ { print }
awk: ^ syntax error
errcount: 2
I also tried awk "/Sam/" test.txt and get same error.
Running just awk '{ print }' test.txt works
I am running on Windows 7 using minGW and my shell is set to:
echo %SHELL%
C:/MinGW/msys/1.0/bin/bash.exe
How do I escape the /Sam/ ? It thinks it is part of the directory to the
exe I think? I tried (trying gawk to see if get better diagnotic msg):
gawk '\/Sam\/ { print $0 }' test.txt
gawk: cmd. line:1: \/Sam\/ { print }
gawk: cmd. line:1: ^ backslash not last character on line
test.txt file contains:
Angus
Lisa
Samuel
Annabel
Jack
Wookie
^ permalink raw reply [flat|nested] 8+ messages in thread
* Re: How to run an awk command on file in emacs - using minGW on Windows
2013-09-17 10:39 How to run an awk command on file in emacs - using minGW on Windows Angus Comber
@ 2013-09-17 11:19 ` Eli Zaretskii
2013-09-17 16:41 ` Angus Comber
0 siblings, 1 reply; 8+ messages in thread
From: Eli Zaretskii @ 2013-09-17 11:19 UTC (permalink / raw)
To: help-gnu-emacs
> Date: Tue, 17 Sep 2013 11:39:59 +0100
> From: Angus Comber <anguscomber@gmail.com>
>
> If I am visiting a file in emacs I want to be able to run a simple awk
> command, eg
>
> awk /Sam/ test.txt
>
> How would I construct this.
"M-! awk /Sam/ test.txt" (without the quotes) works for me.
> I tried:
>
> m-! - to be able to run a shell cmd
>
> awk '/Sam/' test.txt
>
> But then I get this error:
>
> awk: c:/MinGW/msys/1.0/Sam/ { print }
> awk: ^ syntax error
> awk: c:/MinGW/msys/1.0/Sam/ { print }
> awk: ^ syntax error
> errcount: 2
You are using MSYS tools from a native Windows Emacs, and you are
paying the price.
> I also tried awk "/Sam/" test.txt and get same error.
Right, MSYS does that with both flavors of quotes.
> Running just awk '{ print }' test.txt works
Because the argument doesn't start with a slash.
> I am running on Windows 7 using minGW and my shell is set to:
>
> echo %SHELL%
> C:/MinGW/msys/1.0/bin/bash.exe
That's your problem: why do you set shell to the MSYS Bash? I suggest
not to do that. Leave it at the default.
> How do I escape the /Sam/ ? It thinks it is part of the directory to the
> exe I think?
Yes.
Try this:
awk ' /Sam/' test.txt
i.e. an extra blank before the first slash.
But I really suggest not to use MSYS tools from Emacs. There are
native (MinGW) ports available.
^ permalink raw reply [flat|nested] 8+ messages in thread
* Re: How to run an awk command on file in emacs - using minGW on Windows
2013-09-17 11:19 ` Eli Zaretskii
@ 2013-09-17 16:41 ` Angus Comber
2013-09-17 17:20 ` Eli Zaretskii
0 siblings, 1 reply; 8+ messages in thread
From: Angus Comber @ 2013-09-17 16:41 UTC (permalink / raw)
To: Emacs Help
On 17 September 2013 12:19, Eli Zaretskii <eliz@gnu.org> wrote:
> > Date: Tue, 17 Sep 2013 11:39:59 +0100
> > From: Angus Comber <anguscomber@gmail.com>
> >
> > If I am visiting a file in emacs I want to be able to run a simple awk
> > command, eg
> >
> > awk /Sam/ test.txt
> >
> > How would I construct this.
>
> "M-! awk /Sam/ test.txt" (without the quotes) works for me.
>
> > I tried:
> >
> > m-! - to be able to run a shell cmd
> >
> > awk '/Sam/' test.txt
> >
> > But then I get this error:
> >
> > awk: c:/MinGW/msys/1.0/Sam/ { print }
> > awk: ^ syntax error
> > awk: c:/MinGW/msys/1.0/Sam/ { print }
> > awk: ^ syntax error
> > errcount: 2
>
> You are using MSYS tools from a native Windows Emacs, and you are
> paying the price.
>
> > I also tried awk "/Sam/" test.txt and get same error.
>
> Right, MSYS does that with both flavors of quotes.
>
> > Running just awk '{ print }' test.txt works
>
> Because the argument doesn't start with a slash.
>
> > I am running on Windows 7 using minGW and my shell is set to:
> >
> > echo %SHELL%
> > C:/MinGW/msys/1.0/bin/bash.exe
>
> That's your problem: why do you set shell to the MSYS Bash? I suggest
> not to do that. Leave it at the default.
>
> > How do I escape the /Sam/ ? It thinks it is part of the directory to the
> > exe I think?
>
> Yes.
>
> Try this:
>
> awk ' /Sam/' test.txt
>
> i.e. an extra blank before the first slash.
>
*** The extra space fixes it. That is not obvious.
>
> But I really suggest not to use MSYS tools from Emacs. There are
> native (MinGW) ports available.
>
> *** But msys gives me my unix environment. Are you saying install full
Cygwin? Or just remove my %SHELL% env var?
^ permalink raw reply [flat|nested] 8+ messages in thread
* Re: How to run an awk command on file in emacs - using minGW on Windows
2013-09-17 16:41 ` Angus Comber
@ 2013-09-17 17:20 ` Eli Zaretskii
2013-09-18 9:55 ` Angus Comber
0 siblings, 1 reply; 8+ messages in thread
From: Eli Zaretskii @ 2013-09-17 17:20 UTC (permalink / raw)
To: help-gnu-emacs
> Date: Tue, 17 Sep 2013 17:41:07 +0100
> From: Angus Comber <anguscomber@gmail.com>
>
> > Try this:
> >
> > awk ' /Sam/' test.txt
> >
> > i.e. an extra blank before the first slash.
> >
>
> *** The extra space fixes it. That is not obvious.
Of course, it's not obvious. Nothing ever is with MSYS name-mangling.
> > But I really suggest not to use MSYS tools from Emacs. There are
> > native (MinGW) ports available.
> >
> *** But msys gives me my unix environment. Are you saying install full
> Cygwin? Or just remove my %SHELL% env var?
What exactly do you mean by "unix environment" in this context? Why
do you need to set SHELL to point to the MSYS Bash when you are
working in Emacs? Do you actually want the shell (and if so, for what
purposes), or do you want the Unix utilities? If the latter, there
are natively compiled ports of those utilities, just install and use
them.
^ permalink raw reply [flat|nested] 8+ messages in thread
* Re: How to run an awk command on file in emacs - using minGW on Windows
2013-09-17 17:20 ` Eli Zaretskii
@ 2013-09-18 9:55 ` Angus Comber
2013-09-18 10:13 ` Eli Zaretskii
0 siblings, 1 reply; 8+ messages in thread
From: Angus Comber @ 2013-09-18 9:55 UTC (permalink / raw)
To: Eli Zaretskii; +Cc: Emacs Help
OK this is what I just tried:
I removed my PC's %SHELL% variable (set to C:/MinGW/msys/1.0/bin/bash.exe)
I removed this line in my emacs init.el file (emacs init file)
'(shell-file-name "C:/MinGW/msys/1.0/bin/bash.exe")
After doing that I still have same issue and even using ' /Sam/' workaround
doesn't work. So this move doesn't look helpful.
I do have a folder containing native 'unix' tools, eg awk etc in a folder
on my PC. So I have the programs - and path set in env variable.
Is there some step I am missing?
I thought problem with emacs and shell was because it attempted to use
cmd.exe? So I changed shell to bash.exe - and that at least seemed to help.
If you have any suggestions I would love to hear them.
On 17 September 2013 18:20, Eli Zaretskii <eliz@gnu.org> wrote:
> > Date: Tue, 17 Sep 2013 17:41:07 +0100
> > From: Angus Comber <anguscomber@gmail.com>
> >
> > > Try this:
> > >
> > > awk ' /Sam/' test.txt
> > >
> > > i.e. an extra blank before the first slash.
> > >
> >
> > *** The extra space fixes it. That is not obvious.
>
> Of course, it's not obvious. Nothing ever is with MSYS name-mangling.
>
> > > But I really suggest not to use MSYS tools from Emacs. There are
> > > native (MinGW) ports available.
> > >
> > *** But msys gives me my unix environment. Are you saying install full
> > Cygwin? Or just remove my %SHELL% env var?
>
> What exactly do you mean by "unix environment" in this context? Why
> do you need to set SHELL to point to the MSYS Bash when you are
> working in Emacs? Do you actually want the shell (and if so, for what
> purposes), or do you want the Unix utilities? If the latter, there
> are natively compiled ports of those utilities, just install and use
> them.
>
>
^ permalink raw reply [flat|nested] 8+ messages in thread
* Re: How to run an awk command on file in emacs - using minGW on Windows
2013-09-18 9:55 ` Angus Comber
@ 2013-09-18 10:13 ` Eli Zaretskii
2013-09-18 13:52 ` Angus Comber
0 siblings, 1 reply; 8+ messages in thread
From: Eli Zaretskii @ 2013-09-18 10:13 UTC (permalink / raw)
To: help-gnu-emacs
> Date: Wed, 18 Sep 2013 10:55:19 +0100
> From: Angus Comber <anguscomber@gmail.com>
> Cc: Emacs Help <help-gnu-emacs@gnu.org>
>
> I removed my PC's %SHELL% variable (set to C:/MinGW/msys/1.0/bin/bash.exe)
>
> I removed this line in my emacs init.el file (emacs init file)
>
> '(shell-file-name "C:/MinGW/msys/1.0/bin/bash.exe")
>
> After doing that I still have same issue and even using ' /Sam/' workaround
> doesn't work. So this move doesn't look helpful.
First, start with "emacs -Q", since there could be other
customizations in your .emacs that interfere. Then try this:
M-! gawk.exe /Sam/ test.txt
Note: no quote characters around /Sam/, and call 'gawk.exe' directly
(since 'awk' might be a shell script, which again brings the MSYS
shell into the play).
If this does not work, then your gawk.exe is probably an MSYS program,
so you have the same filename-mangling problem again. You can find a
native port of Gawk here:
http://sourceforge.net/projects/ezwinports/files/gawk-4.1.0-2-w32-bin.zip/download
Try using it instead.
In general, remove the MSYS bin directory from your PATH, at least
when you are using Emacs, and install native Windows ports of the Unix
utilities that you need, putting them in a directory where Emacs can
find them.
^ permalink raw reply [flat|nested] 8+ messages in thread
* Re: How to run an awk command on file in emacs - using minGW on Windows
2013-09-18 10:13 ` Eli Zaretskii
@ 2013-09-18 13:52 ` Angus Comber
2013-09-18 15:00 ` Eli Zaretskii
0 siblings, 1 reply; 8+ messages in thread
From: Angus Comber @ 2013-09-18 13:52 UTC (permalink / raw)
To: Eli Zaretskii; +Cc: Emacs Help
On 18 September 2013 11:13, Eli Zaretskii <eliz@gnu.org> wrote:
> > Date: Wed, 18 Sep 2013 10:55:19 +0100
> > From: Angus Comber <anguscomber@gmail.com>
> > Cc: Emacs Help <help-gnu-emacs@gnu.org>
> >
> > I removed my PC's %SHELL% variable (set to
> C:/MinGW/msys/1.0/bin/bash.exe)
> >
> > I removed this line in my emacs init.el file (emacs init file)
> >
> > '(shell-file-name "C:/MinGW/msys/1.0/bin/bash.exe")
> >
> > After doing that I still have same issue and even using ' /Sam/'
> workaround
> > doesn't work. So this move doesn't look helpful.
>
> First, start with "emacs -Q", since there could be other
> customizations in your .emacs that interfere. Then try this:
>
> M-! gawk.exe /Sam/ test.txt
>
> Note: no quote characters around /Sam/, and call 'gawk.exe' directly
> (since 'awk' might be a shell script, which again brings the MSYS
> shell into the play).
>
> If this does not work, then your gawk.exe is probably an MSYS program,
> so you have the same filename-mangling problem again. You can find a
> native port of Gawk here:
>
>
> http://sourceforge.net/projects/ezwinports/files/gawk-4.1.0-2-w32-bin.zip/download
>
> Try using it instead.
>
> In general, remove the MSYS bin directory from your PATH, at least
> when you are using Emacs, and install native Windows ports of the Unix
> utilities that you need, putting them in a directory where Emacs can
> find them.
>
>
***
I really can't thank you enough. Updating the awk versions has fixed the
issue. I have removed shell from emacs config and everything is working
file (after awk program update as per your link).
Many thanks.
^ permalink raw reply [flat|nested] 8+ messages in thread
* Re: How to run an awk command on file in emacs - using minGW on Windows
2013-09-18 13:52 ` Angus Comber
@ 2013-09-18 15:00 ` Eli Zaretskii
0 siblings, 0 replies; 8+ messages in thread
From: Eli Zaretskii @ 2013-09-18 15:00 UTC (permalink / raw)
To: help-gnu-emacs
> Date: Wed, 18 Sep 2013 14:52:53 +0100
> From: Angus Comber <anguscomber@gmail.com>
> Cc: Emacs Help <help-gnu-emacs@gnu.org>
>
> > http://sourceforge.net/projects/ezwinports/files/gawk-4.1.0-2-w32-bin.zip/download
> >
> > Try using it instead.
> >
> > In general, remove the MSYS bin directory from your PATH, at least
> > when you are using Emacs, and install native Windows ports of the Unix
> > utilities that you need, putting them in a directory where Emacs can
> > find them.
> >
> >
> ***
> I really can't thank you enough. Updating the awk versions has fixed the
> issue. I have removed shell from emacs config and everything is working
> file (after awk program update as per your link).
>
> Many thanks.
Glad I could be of help. Good luck, and happy hacking!
^ permalink raw reply [flat|nested] 8+ messages in thread
end of thread, other threads:[~2013-09-18 15:00 UTC | newest]
Thread overview: 8+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2013-09-17 10:39 How to run an awk command on file in emacs - using minGW on Windows Angus Comber
2013-09-17 11:19 ` Eli Zaretskii
2013-09-17 16:41 ` Angus Comber
2013-09-17 17:20 ` Eli Zaretskii
2013-09-18 9:55 ` Angus Comber
2013-09-18 10:13 ` Eli Zaretskii
2013-09-18 13:52 ` Angus Comber
2013-09-18 15:00 ` Eli Zaretskii
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).