nixCraft Linux Forum

nixCraft

Linux Tech Support Forum

How to pass shell variable to awk program

This is a discussion on How to pass shell variable to awk program within the Shell scripting forums, part of the Development/Scripting category; Is it possible to pass a shell variable to an awk program? If so please gimme example...


Go Back   nixCraft Linux Forum > Development/Scripting > Shell scripting

Register FAQ Members List Calendar Forgotten your password? Mark Forums Read
  #1 (permalink)  
Old 02-05-2006, 09:56 PM
Guest
 
Posts: n/a
Default How to pass shell variable to awk program

Is it possible to pass a shell variable to an awk program? If so please gimme example
Reply With Quote
Sponsored Links
  #2 (permalink)  
Old 02-08-2006, 08:28 PM
Vindicator
Guest
 
Posts: n/a
Default Passing a Shell Variable to AWK

Try this:
echo $PATH | awk -F: '{print NF}'

This should pass your current PATH to awk and it will return the number of directories.
Reply With Quote
  #3 (permalink)  
Old 02-08-2006, 10:13 PM
monk's Avatar
Senior Member
User
 
Join Date: Jan 2005
Location: Tibet
My distro: Debian GNU/Linux
Posts: 482
Rep Power: 5
monk will become famous soon enough monk will become famous soon enough
Default

You can try out something as follows:
Code:
echo data | awk '{ print ENVIRON["USER"] }'
Read man page of awk for more info
Reply With Quote
  #4 (permalink)  
Old 05-27-2006, 03:46 AM
Junior Member
 
Join Date: May 2006
Posts: 1
Rep Power: 0
ahmed
Default

You can pass a variable to a awk by using the -v option.. which is for variable.
Reply With Quote
  #5 (permalink)  
Old 06-23-2006, 06:11 AM
Junior Member
 
Join Date: Jun 2006
Posts: 2
Rep Power: 0
Doc_RuNNeR
Default

It is possible and it can be a solution (i think)

#your shell script
.........................
.........................
.........................

awk -v var1=`echo $nam_var1` -v var2=`echo $nam_var2` .............

remember to delete your script var when you finish Bye
Reply With Quote
Reply

Bookmarks


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)

 
Thread Tools
Display Modes

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

Similar Threads

Thread Thread Starter Forum Replies Last Post
environmental variable myfoot CentOS / RHEL / Fedora 1 02-01-2008 07:14 AM
Passing value from variable while its expected from keyboard unix11 Shell scripting 3 02-22-2007 03:36 PM
SED pass a output line to another cillo Shell scripting 6 11-01-2006 02:59 PM
user pass word sparky Shell scripting 1 06-26-2006 08:19 PM
HTML variable nathan86 Linux software 3 03-23-2005 01:29 PM


All times are GMT +5.5. The time now is 07:25 PM.


Powered by vBulletin® Version 3.7.4 - Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Search Engine Optimization by vBSEO 3.2.0

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36