LinuxQuestions.org
Review your favorite Linux distribution.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - General
User Name
Password
Linux - General This Linux forum is for general Linux questions and discussion.
If it is Linux Related and doesn't seem to fit in any other forum then this is the place.

Notices


Reply
  Search this Thread
Old 04-06-2010, 02:04 PM   #1
mmcc0912
Member
 
Registered: Mar 2010
Posts: 37

Rep: Reputation: 0
Passing $i from for into awk print


Some relevant posts from LQ (passing-vars-awk-366290 and passing-shell-variable-into-awk-syntax-correct-interpretation-562973)

I am not getting this to output. The 2nd one seemed to be spot on, but with several manipulations, the output is blank. My purpouse, to run an aureport -l and have it insert the hostname.

Code:
for i in node1 node2 node3
        do
        ssh $i aureport -l -i -ts yesterday -te today | awk -F " " '{ print $2 " " $3 " " $4 " " $5 " " $6 " " $7 " " $8 }' | grep "/"
        done
Above, this is what works, but trying to have the output lines start with the node name.

I tried passing the $i in the form of:
Code:
awk -F " " -v i="$i" '$1 == i { print...
(with the option -F in multiple places and without -F) and this is when I get the blank results.

The postings mentioned, they were 3-5 years old and maybe there is something updated since then? Too old to add onto imho.

I'm all for digging on this, if it's me getting the quirks right .. feel free to let it stew for a bit. If there's a better way, pass a nugget over to get me started and I'll work on it. Mixture of RHEL4 and RHEL5 nodes and the end result is to use each nodes output into a master file, make a report and store in a DB.

Thanks !
 
Old 04-06-2010, 03:12 PM   #2
acid_kewpie
Moderator
 
Registered: Jun 2001
Location: UK
Distribution: Gentoo, RHEL, Fedora, Centos
Posts: 43,417

Rep: Reputation: 1985Reputation: 1985Reputation: 1985Reputation: 1985Reputation: 1985Reputation: 1985Reputation: 1985Reputation: 1985Reputation: 1985Reputation: 1985Reputation: 1985
well -F is irrelevant for what you're asking, it's only the -v option you need to worry about, and is how you're best off to get the variable into awk. just "awk -v var=$i ..." should be fine.
 
Old 04-06-2010, 04:23 PM   #3
mmcc0912
Member
 
Registered: Mar 2010
Posts: 37

Original Poster
Rep: Reputation: 0
Thanks Chris. Young to Linux and always used -F option for the delimiter, sorta a standard. Mentioned it also incase it may have any interference. I'll kick around on it as time allows and see what comes about..
 
  


Reply



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 On
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
How do I - not print - in awk? ZimMonkey Programming 10 08-21-2009 07:11 PM
passing awk output to $variable for shell script? NewnanNOC Programming 3 10-23-2008 02:08 PM
passing a shell variable into awk - syntax for correct interpretation? johnpaulodonnell Programming 3 06-19-2007 12:13 PM
passing vars to awk schneidz Programming 6 09-25-2005 01:52 PM
script problem while using awk and passing varibales ulto Programming 6 04-23-2004 11:58 AM

LinuxQuestions.org > Forums > Linux Forums > Linux - General

All times are GMT -5. The time now is 06:31 PM.

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
Open Source Consulting | Domain Registration