LinuxQuestions.org
Welcome to the most active Linux Forum on the web.
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices

Reply
 
Search this Thread
Old 12-23-2010, 09:49 AM   #1
chogall
LQ Newbie
 
Registered: Dec 2010
Posts: 5

Rep: Reputation: 0
Pass a shell variable to an AWK command


Hi!

I have the following code :

Code:
 
E_BADARGS=65

 if [ $# -ne 2 ] ; then
	echo "Wrong number of arguments"
	exit $E_BADARGS
 else

	for file in TputAbort$1$2.dat
	do

	awk '{sum+=$1}END{print "throughput parallel: "  sum/NR " op/s"}' $file
	awk '{sum+=$2}END{print "abort parallel: "  sum/NR " op/s"}' $file

	done
 fi

What I want to do is to use the arguments I pass to my shell script inside the AWK command. I would like to replace the string "parallel" by the first argument which would be $1. But of course, this $1 (the 1st argument) is not the same as the $1 I use in "sum+=$1" (which represents the first field in the file $file.

Anyone has an idea ?

Thanks in advance!
 
Old 12-23-2010, 10:12 AM   #2
grail
Guru
 
Registered: Sep 2009
Location: Perth
Distribution: Manjaro
Posts: 7,442

Rep: Reputation: 1880Reputation: 1880Reputation: 1880Reputation: 1880Reputation: 1880Reputation: 1880Reputation: 1880Reputation: 1880Reputation: 1880Reputation: 1880Reputation: 1880
Check out '-v' option for awk.
 
  


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
awk using a shell variable? elfoozo Programming 11 07-24-2010 02:47 AM
[SOLVED] awk: how can I assign value to a shell variable inside awk? quanba Programming 6 03-23-2010 02:18 AM
awk and shell variable markux Linux - Server 6 01-19-2009 03:54 AM
how to pass an external variable to awk??? akitty Programming 7 11-13-2008 08:47 AM
pass value from awk back to bash shell cjs_pro Programming 2 03-07-2005 04:53 PM


All times are GMT -5. The time now is 08:42 PM.

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