Difficulty embedding variable within AWK


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Difficulty embedding variable within AWK
# 1  
Old 02-14-2012
Difficulty embedding variable within AWK

Hi,
I am working on a parsing script but cannot figure out how to accomplish this. Here is a simplified version of the script:
Code:
#!/bin/bash
DS=$1
DS=`expr $DS \* 2`
DS=`expr $DS + 7`

cat $FILENAME | awk '/<row><v> +[0-9]/' | awk '{printf("%.0f %.0f\n", $6, $9)}'

The problem is that I want the $9 (the 9th column) to instead be the "DS"-th column. For example, if DS=2, then it should be $11. Any ideas on how to specify the variable name ($9) to be determined by another variable?

I would really appreciate any advice.
Thanks.
- Nisrak

Last edited by Franklin52; 02-15-2012 at 03:32 AM.. Reason: Please use code tags for code and data samples, thank you
# 2  
Old 02-14-2012
Try this:

Code:
awk -vDS=$DS '/<row><v> +[0-9]/ { printf("%.0f %.0f\n", $6, $(9+DS))}' $FILENAME

# 3  
Old 02-14-2012
That did the trick! Thanks for the help.
- Nisrak
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Embedding JPEG image to the body file

hi, I am trying to embed an image to the body of the email, but the image is not visible. echo "<html> <body> <style> body {background-color:blue} </style> <h1>hello</h1> <center> <img... (1 Reply)
Discussion started by: ATWC
1 Replies

2. UNIX for Advanced & Expert Users

Embedding code into ssh keys

Hi Its been a long time since I worked with ssh keys containing embedded shell commands and cannot remember how it is done. Does anyone know of any sites that have a good tutorial on the subject? I'm not having much luck searching Google for it. Incidentally, searching this forum for the... (6 Replies)
Discussion started by: steadyonabix
6 Replies

3. Shell Programming and Scripting

difficulty with awk

hello folks, i am stuck with this awk command. i need to calculate the sum of a column of values on a flatfile and i am using the following command : awk -F"|" '{x += $10} END {print "Sum: "x}' standard_csv_file1.out that flatfile contains 180 fields and i am getting the... (5 Replies)
Discussion started by: jdsony
5 Replies

4. Shell Programming and Scripting

Need help embedding Unix commands in a shell script

Hi Folks, I have a text file which may or may not have any data. I would like to email the file, via a Korn shell script, if the file is not empty. I am fiddling around with the wc -l command, but no luck so far. The pseudo code is as follows count=`wc -l test.txt` if cat test.txt... (4 Replies)
Discussion started by: rogers42
4 Replies

5. Shell Programming and Scripting

using awk for setting variable but change the output of this variable within awk

Hi all, Hope someone can help me out here. I have this BASH script (see below) My problem lies with the variable path. The output of the command find will give me several fields. The 9th field is the path. I want to captured that and the I want to filter this to a specific level. The... (6 Replies)
Discussion started by: Cowardly
6 Replies

6. Shell Programming and Scripting

Embedding HTML in Perl script

My webpage is hosted from perlscript(homepage.pl), i want to add piece of html code in the footer of the homepage. I simply pasted the html code at the end of the perl script as below... ======================================================== close(OUTSQL); ... (4 Replies)
Discussion started by: paventhan
4 Replies

7. UNIX Desktop Questions & Answers

Embedding file output into a script

Hello. I found a Unix script on this site that calculates a date that is 2 months earlier from today. I'm using that script and writing the value to a file called 2monthsago.txt. I want to use that value in another script. Below is my attempt at doing that and the results. My Script: ... (1 Reply)
Discussion started by: Colel2
1 Replies

8. Shell Programming and Scripting

Embedding a command with SSH

Hi I am trying to run a script centrally that will go out and set the network management ip address on all my Sun boxes running Solaris. We have decided that the network management address will be the boxes main IP address but the first octet as a 172 rather than a 10, so for example ifconfig -a... (2 Replies)
Discussion started by: hcclnoodles
2 Replies

9. Programming

Embedding xnest in C code

I hope I am posting this in the right section. I have c file that is using the motif GUI toolkit to draw widgets and things of that sort. I also have another program that runs with xnest. I need to figure out a way to place that xnest program in my c code so that it exists in the window that the... (4 Replies)
Discussion started by: lesnaubr
4 Replies

10. Shell Programming and Scripting

Embedding Perl construct in ksh...

Hi, I have an embedded Perl construct in a korn script. However, I cannot seem to access the shell variables that were declared outside this Perl section. This is how my script is written....I have also tried back-ticks where I assign the shell variable to my local perl variable, still... (1 Reply)
Discussion started by: svetlur
1 Replies
Login or Register to Ask a Question