LinuxQuestions.org
Did you know LQ has a Linux Hardware Compatibility List?
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 01-25-2007, 06:22 AM   #1
johnpaulodonnell
Member
 
Registered: Jun 2006
Location: Galway
Distribution: Suse 10.1
Posts: 114

Rep: Reputation: 15
how to pipe/redirect awk output into a variable?


Hi.

I have a simple awk command to read the number of records in a file which is passed to it. I'd like to then save this output as a variable within a bash script. How is this done? The pipe I use below doesn't work.

awk '{ ++x } END { print x }' file_name | read my_variable

Similarly I get an error when I try:

read my_variable < awk '{ ++x } END { print x }' file_name

Thanks.
 
Old 01-25-2007, 06:49 AM   #2
Guttorm
Senior Member
 
Registered: Dec 2003
Location: Trondheim, Norway
Distribution: Debian and Ubuntu
Posts: 1,115

Rep: Reputation: 218Reputation: 218Reputation: 218
Hi

my_variable=$(command)

try:
my_variable=$(awk '{ ++x } END { print x }' file_name)
 
Old 01-25-2007, 06:54 AM   #3
johnpaulodonnell
Member
 
Registered: Jun 2006
Location: Galway
Distribution: Suse 10.1
Posts: 114

Original Poster
Rep: Reputation: 15
That's it.

Thanks!
 
  


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
How to redirect streams to the variable? Rostfrei Programming 3 01-20-2007 03:51 AM
Bash Awk Variable problem _hadi_ Programming 5 12-13-2006 12:25 AM
awk on a variable onradius Programming 8 02-22-2006 08:34 AM
Accessing Shell variable in awk script dileepkk Linux - General 1 10-07-2004 07:47 AM
Pipe inside variable isn't working in bash Reginald0 Linux - General 5 01-30-2004 09:43 AM


All times are GMT -5. The time now is 03:28 AM.

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