LinuxQuestions.org
Help answer threads with 0 replies.
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 06-16-2011, 06:47 PM   #1
kristo5747
Member
 
Registered: Jul 2010
Location: Earth
Distribution: Ubuntu 11.04 (Natty Narwhal)
Posts: 31

Rep: Reputation: 0
pass shell parameters to awk does not work


Why does this work

Code:
    for myfile in `find . -name "R*VER" -mtime +1`
    do
       SHELLVAR=`grep ^err $myfile || echo "No error"`
       ECHO $SHELLVAR
    done
and outputs

Code:
    No error
    err ->BIST Login Fail 3922 err
    No error
    err ->IR Remote Key 1 3310 err
But this does not

Code:
    for myfile in `find . -name "R*VER" -mtime +1`
    do
       SHELLVAR=`grep ^err $myfile || echo "No error"`
       awk -v awkvar=${SHELLVAR} '{print awkvar}'
    done
and outputs

Code:
    awk: cmd. line:1: fatal: cannot open file `{print awkvar}' for reading (No such file or directory)
What am I missing?
 
Old 06-16-2011, 07:50 PM   #2
grail
LQ Guru
 
Registered: Sep 2009
Location: Perth
Distribution: Manjaro
Posts: 9,530

Rep: Reputation: 2897Reputation: 2897Reputation: 2897Reputation: 2897Reputation: 2897Reputation: 2897Reputation: 2897Reputation: 2897Reputation: 2897Reputation: 2897Reputation: 2897
Quote:
What am I missing?
You gave your own answer:
Quote:
awk: cmd. line:1: fatal: cannot open file `{print awkvar}' for reading (No such file or directory)
By default a normal awk expression / action will attempt to work on a file. I presume you are going to do something
more interesting with the awk later (as the current idea serves no purpose that echo cannot achieve) so
if you do not wish to pipe data into the awk or read from a file, you can use the BEGIN stanza:
Code:
awk 'BEGIN{print "hello"}'

Last edited by grail; 06-20-2011 at 07:05 PM.
 
Old 06-20-2011, 11:40 AM   #3
kristo5747
Member
 
Registered: Jul 2010
Location: Earth
Distribution: Ubuntu 11.04 (Natty Narwhal)
Posts: 31

Original Poster
Rep: Reputation: 0
Quote:
Originally Posted by grail View Post
By default a normal awk expression / action will attempt to work on a file.
I changed to a while loop and fed $myfile to the awk command. It worked. Thank you for your time.
 
  


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
Pass a shell variable to an AWK command chogall Programming 1 12-23-2010 10:12 AM
how to pass MySQL user/pass securely in shell script? digity Linux - Newbie 5 01-07-2010 05:48 AM
run CGI and pass GET parameters extasic Programming 6 10-17-2008 08:53 AM
pass value from awk back to bash shell cjs_pro Programming 2 03-07-2005 04:53 PM
pass parameters to shell scripts ? qwijibow Linux - Newbie 2 08-07-2003 07:27 AM

LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie

All times are GMT -5. The time now is 01:14 AM.

Main Menu
Advertisement
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
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration