The UNIX and Linux Forums  
Hello and Welcome from United States to the UNIX and Linux Forums! Thank You for Visiting and Joining Our Global Community.

Go Back   The UNIX and Linux Forums > Top Forums > UNIX for Advanced & Expert Users
.
google unix.com



UNIX for Advanced & Expert Users Expert-to-Expert. Learn advanced UNIX, UNIX commands, Linux, Operating Systems, System Administration, Programming, Shell, Shell Scripts, Solaris, Linux, HP-UX, AIX, OS X, BSD.

More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
Passing a variable from a child script back to the parent Andy82 Shell Programming and Scripting 3 05-26-2008 10:52 PM
passing asterisk to a script as variable GKnight Shell Programming and Scripting 9 04-02-2008 11:32 AM
passing variable to my script aladdin UNIX for Dummies Questions & Answers 5 06-18-2007 10:34 AM
passing ip address as a variable to script for ftp Gerry405 UNIX for Dummies Questions & Answers 2 09-01-2005 06:26 AM
passing awk variable to the shell script bcheaib Shell Programming and Scripting 3 07-21-2004 11:00 AM

Closed Thread
English Japanese Spanish French German Portuguese Italian Dutch Swedish Russian Norwegian Hungarian Hebrew Danish Bulgarian Greek Powered by Powered by Google
 
LinkBack Thread Tools Search this Thread Rate Thread Display Modes
  #1 (permalink)  
Old 09-05-2006
Khoomfire Khoomfire is offline
Registered User
  
 

Join Date: Aug 2005
Posts: 68
Passing a variable into an awk script

Hello all,
I'm trying to run a script of this format -

for i in $(cat <file>); do
grep $i <file1>|awk '{print $i, $1, $2}'

It's not working - does anyone know how this can be done?

Khoom
  #2 (permalink)  
Old 09-05-2006
vgersh99's Avatar
vgersh99 vgersh99 is offline Forum Staff  
Moderator
  
 

Join Date: Feb 2005
Location: Boston, MA
Posts: 5,122
Quote:
Originally Posted by Khoomfire
Hello all,
I'm trying to run a script of this format -

for i in $(cat <file>); do
grep $i <file1>|awk '{print $i, $1, $2}'

It's not working - does anyone know how this can be done?

Khoom
Code:
#!/bin/ksh
for i in $(< file ); do
   nawk -v myI="${i}" '$0 ~ myI { print myI, $1, $2 }'
done
  #3 (permalink)  
Old 09-05-2006
Khoomfire Khoomfire is offline
Registered User
  
 

Join Date: Aug 2005
Posts: 68
Quote:
Originally Posted by vgersh99
Code:
#!/bin/ksh
for i in $(< file ); do
   nawk -v myI="${i}" '$0 ~ myI { print myI, $1, $2 }'
done
ksh: nawk: not found


<sigh>
  #4 (permalink)  
Old 09-05-2006
vgersh99's Avatar
vgersh99 vgersh99 is offline Forum Staff  
Moderator
  
 

Join Date: Feb 2005
Location: Boston, MA
Posts: 5,122
try with plain 'awk'
  #5 (permalink)  
Old 09-05-2006
Khoomfire Khoomfire is offline
Registered User
  
 

Join Date: Aug 2005
Posts: 68
Quote:
Originally Posted by Khoomfire
Hello all,
I'm trying to run a script of this format -

for i in $(cat <file>); do
grep $i <file1>|awk '{print $i, $1, $2}'

It's not working - does anyone know how this can be done?

Khoom
I have it now - thanks to vgersh99 for the inspiration

for i in $(cat <file>); do
grep $i <file1>|awk -v string=$i '{print string, $1, $2}'
  #6 (permalink)  
Old 09-05-2006
vgersh99's Avatar
vgersh99 vgersh99 is offline Forum Staff  
Moderator
  
 

Join Date: Feb 2005
Location: Boston, MA
Posts: 5,122
  1. why do you need a 'cat'?
  2. why do you need a 'grep'?
Closed Thread

Bookmarks

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes Rate This Thread
Rate This Thread:

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
Trackbacks are On
Pingbacks are On
Refbacks are On




All times are GMT -4. The time now is 02:17 PM.


Powered by: vBulletin, Copyright ©2000 - 2006, Jelsoft Enterprises Limited. Language Translations Powered by .
vBCredits v1.4 Copyright ©2007 - 2008, PixelFX Studios
The UNIX and Linux Forums Content Copyright ©1993-2009. All Rights Reserved.Ad Management by RedTyger

Content Relevant URLs by vBSEO 3.2.0