LinuxQuestions.org
Support LQ: Use code LQ3 and save $3 on Domain Registration
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie
User Name
Password
Linux - Newbie This Linux forum is for members that are new to Linux.
Just starting out and have a question? If it is not in the man pages or the how-to's this is the place!

Notices

Reply
 
Search this Thread
Old 03-03-2011, 04:33 AM   #1
PaulVanLil
LQ Newbie
 
Registered: Mar 2011
Location: Keerbergen, Belgium
Posts: 3

Rep: Reputation: 0
AWK runs in command line, but not in script


Hi,

I am trying to execute an awk script which is called by a shell script. The result is that it always responds with << ^ invalid char ' ' in expression >>

As I do not have command line access, I use a php script as go-around.

On the command line,
Code:
awk --version
gives the following output:

Code:
Command: awk --version
GNU Awk 3.1.3
Copyright (C) 1989, 1991-2003 Free Software Foundation.

This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2 of the License, or
(at your option) any later version.

This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.

You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
So, awk is installed on the server.

On the command line
Code:
awk "BEGIN { print \"Don't Panic!\" }"
results in:

Code:
Command: awk "BEGIN { print \"Don't Panic!\" }"
Don't Panic!
OK, I do not panic, AWK commands are executed.

Next is to put the awk-command in a script called advice.awk
The commands is:
Code:
BEGIN { print "Don't Panic!" }
advice.awk is in the same directory as run.php (which starts the command line) and has chmod 777.

When I give the command
Code:
awk -f advice.awk
the result is:
Code:
Command: awk -f advice.awk
awk: advice.awk:1: BEGIN { print "Don't Panic!" }
awk: advice.awk:1: ^ invalid char ' ' in expression
Thus, after two days of searching, I start to panic!

What is going wrong?

Thanks in advance,
Paul
 
Old 03-03-2011, 05:01 AM   #2
ryoken31
LQ Newbie
 
Registered: Apr 2007
Location: Ontario
Posts: 6

Rep: Reputation: 2
What are you using to create advice.awk? If you're not already, try using vi or nano to create the file. Some text editors add hidden characters at the start/end of text documents that could be causing the issue. I was not able to reproduce the problem on my machine using the same version of awk as you. I only have command line access and was using nano to create the file.
 
1 members found this post helpful.
Old 03-03-2011, 05:14 AM   #3
PaulVanLil
LQ Newbie
 
Registered: Mar 2011
Location: Keerbergen, Belgium
Posts: 3

Original Poster
Rep: Reputation: 0
I am using WinVi as editor.

I'll try nano as editor.

Thanks,
Paul
 
Old 03-03-2011, 05:25 AM   #4
PaulVanLil
LQ Newbie
 
Registered: Mar 2011
Location: Keerbergen, Belgium
Posts: 3

Original Poster
Rep: Reputation: 0
OK, using nano as editor is doing the job.

Thanks,
Paul
 
Old 03-03-2011, 07:07 AM   #5
grail
Guru
 
Registered: Sep 2009
Location: Perth
Distribution: Manjaro
Posts: 7,492

Rep: Reputation: 1892Reputation: 1892Reputation: 1892Reputation: 1892Reputation: 1892Reputation: 1892Reputation: 1892Reputation: 1892Reputation: 1892Reputation: 1892Reputation: 1892
Just an addon for you, you can list the interpreter at the top of the script the same as you would in say a bash script:
Code:
#!/usr/bin/awk -f
Obviously path needs to be where your awk is located
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
[SOLVED] PHP script runs from the command line...but not on Apache custangro Linux - Enterprise 3 07-02-2010 06:38 PM
awk command line: blank line record sep, new line field sep robertmarkbram Programming 4 02-21-2010 05:25 AM
how to replace line of file with another line using awk in shell script amit_pansuria Programming 3 03-29-2009 09:43 AM
Script runs fine from command line, but not when attempted from Cron hwest Linux - Newbie 8 12-11-2008 06:48 PM
script runs fine from a command line, but doesn't work from cron? kleptophobiac Linux - Software 5 05-03-2004 04:14 PM


All times are GMT -5. The time now is 04:26 PM.

Main Menu
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
identi.ca: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration