LinuxQuestions.org
Welcome to the most active Linux Forum on the web.
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 07-10-2009, 03:43 AM   #1
EmrldDrgn
Member
 
Registered: Oct 2008
Posts: 40

Rep: Reputation: 16
Run AWK script on contents of a variable


I have an AWK script (tiny, nothing special, passed on command line) that I want to run with the contents of a variable instead of the contents of a file. How can I do this? It seems like it should be really simple, but I've been trying for hours!

Thanks!
 
Old 07-10-2009, 04:06 AM   #2
colucix
LQ Guru
 
Registered: Sep 2003
Location: Bologna
Distribution: CentOS 6.5 OpenSuSE 12.3
Posts: 10,509

Rep: Reputation: 1978Reputation: 1978Reputation: 1978Reputation: 1978Reputation: 1978Reputation: 1978Reputation: 1978Reputation: 1978Reputation: 1978Reputation: 1978Reputation: 1978
Maybe something like
Code:
echo $my_var | awk -f script.awk
 
Old 07-10-2009, 04:07 AM   #3
EmrldDrgn
Member
 
Registered: Oct 2008
Posts: 40

Original Poster
Rep: Reputation: 16
As always, I figured it out right after posting. Unless someone knows a better way than doing:

echo "$var" | awk '{script}'

?
 
Old 07-10-2009, 05:05 AM   #4
xeleema
Member
 
Registered: Aug 2005
Location: D.i.t.h.o, Texas
Distribution: Slackware 13.x, rhel3/5, Solaris 8-10(sparc), HP-UX 11.x (pa-risc)
Posts: 987
Blog Entries: 4

Rep: Reputation: 252Reputation: 252Reputation: 252
Jeepers!

Holy cow!
/me facepalm
I've got a script I've been working on for a week or so, and I kept scratching my head on something similar!

Thanks guys!
 
  


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
grep a shell script variable contents kushalkoolwal Programming 8 02-04-2009 06:15 AM
passing awk output to $variable for shell script? NewnanNOC Programming 3 10-23-2008 02:08 PM
Using global variable in awk (bash script) kopeda Programming 2 04-24-2007 01:47 AM
cannot export result from awk into a variable in a bash script Emmanuel_uk Linux - Newbie 4 03-07-2005 01:54 AM
Accessing Shell variable in awk script dileepkk Linux - General 1 10-07-2004 07:47 AM

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

All times are GMT -5. The time now is 04:10 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
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration