delorie.com/archives/browse.cgi   search  
Mail Archives: cygwin/2009/07/29/10:11:52

X-Recipient: archive-cygwin AT delorie DOT com
X-SWARE-Spam-Status: No, hits=-1.8 required=5.0 tests=AWL,BAYES_00,SARE_MSGID_LONG40,SPF_PASS
X-Spam-Check-By: sourceware.org
MIME-Version: 1.0
In-Reply-To: <000001ca0fa2$62df2430$289d6c90$@com>
References: <000001ca0fa2$62df2430$289d6c90$@com>
Date: Wed, 29 Jul 2009 10:11:29 -0400
Message-ID: <f60fe000907290711t22155ad2ibb23a00d019dafce@mail.gmail.com>
Subject: Re: AWK from a batch file
From: "Mark J. Reed" <markjreed AT gmail DOT com>
To: cygwin AT cygwin DOT com
X-IsSubscribed: yes
Mailing-List: contact cygwin-help AT cygwin DOT com; run by ezmlm
List-Id: <cygwin.cygwin.com>
List-Unsubscribe: <mailto:cygwin-unsubscribe-archive-cygwin=delorie DOT com AT cygwin DOT com>
List-Subscribe: <mailto:cygwin-subscribe AT cygwin DOT com>
List-Archive: <http://sourceware.org/ml/cygwin/>
List-Post: <mailto:cygwin AT cygwin DOT com>
List-Help: <mailto:cygwin-help AT cygwin DOT com>, <http://sourceware.org/ml/#faqs>
Sender: cygwin-owner AT cygwin DOT com
Mail-Followup-To: cygwin AT cygwin DOT com
Delivered-To: mailing list cygwin AT cygwin DOT com

On Tue, Jul 28, 2009 at 12:42 PM, Matthew Swanson wrote:
> I am attempting to run AWK in a bash window through a Windows batch file.=
 =C2=A0I
> am using:
>
> echo awk -v FS=3D',' -v OFS=3D',' '^{ > awk.s
> echo =C2=A0 =C2=A0if ^($2 ~ /^^[0-9]*$/^)>> awk.s
> echo =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0print $0 ^>^> "good_file.tx=
t">> awk.s
> echo =C2=A0 =C2=A0else>> awk.s
> echo =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0print $0 ^>^> "bad_file.txt=
">> awk.s
> echo ^}' input_file.txt>> awk.s

OK, so you are creating a bash script from CMD.  Invoking it outside
of Cygwin means the normal bash startup files are not run, so $PATH is
not set, so it can't find any commands.  Replace "awk" with "/bin/awk"
and you should be good, apart from the lack of execute permission.

The second problem is that CMD's "echo" appends carraige returns.
Add these commands to fix both that problem and the execute permission
one:

\cygwin\bin\d2u awk.s
\cygwin\bin\chmod +x awk.s

--=20
Mark J. Reed <markjreed AT gmail DOT com>

--
Problem reports:       http://cygwin.com/problems.html
FAQ:                   http://cygwin.com/faq/
Documentation:         http://cygwin.com/docs.html
Unsubscribe info:      http://cygwin.com/ml/#unsubscribe-simple

- Raw text -


  webmaster     delorie software   privacy  
  Copyright © 2019   by DJ Delorie     Updated Jul 2019