passing variable values to awk command


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting passing variable values to awk command
# 1  
Old 05-22-2008
passing variable values to awk command

Hi,

I have a situation where I have to specify a different value to an awk command, I beleive i have the gist of this done, however I am not able to get this correct. Here is what I have so far

Code:
echo $id
065859555

This value occurs in a "pipe" delimited file in postition 8. Hence I would have something like this in the code

Code:
awk -vi="$id" '{ $8 == $i }' file_1

yields the following output

Code:
awk: 0602-538 The field 65859555 must be in the range 0 to 1024.
 The input line number is 1. The file is HMA_tp.unl.
 The source line number is 1.

In the file "file_1" the value of $id is there in column "8" of the file in a certain record. Can someone please help determine how to perform this search? Thanks in advance

Jerardfjay
# 2  
Old 05-22-2008
pipe delimited and variable
Code:
awk -F'|' -v value="$id" '{ $8==value} ' oldfile > newfile

no $ in front of value
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Cut command with dynamic passing of delimiter and position values

Hi All, We have a requirement of picking nth position value by using cut command. value would be delimited by any symbols. We have to pass delimited value and postition to get the value in a string. ex. echo "A,B,C,D,E" |cut -d "," -f3 echo "A|B|C|D|E"|cut -d "|" -f2 Kindly frame the... (5 Replies)
Discussion started by: KK230689
5 Replies

2. Shell Programming and Scripting

awk with passing variable

I have file called in in.txt contains with the below lines I want to display the lines between the value which I would be passing. one two three four five ten six seven eight Expected output if I have passed one and ten two three four five (8 Replies)
Discussion started by: mychbears
8 Replies

3. Shell Programming and Scripting

awk programming -Passing variable to awk for loop

Hi All, I am new to AWK programming. I have the following for loop in my awk program. cat printhtml.awk: BEGIN -------- <some code here> END{ ----------<some code here> for(N=0; N<H; N++) { for(M=5; M<D; M++) print "\t" D ""; } ----- } ... (2 Replies)
Discussion started by: ctrld
2 Replies

4. Shell Programming and Scripting

Passing multiple column values to UNIX variable

sqlplus -s $USER_ID@$SID/$PWD<<EOF>sql_1.txt set feedback off set heading off select 114032 as c_1 from dual ; EOF for i in `cat sql_1.txt` do sh script_1.sh $i Currently i am passing one column value to the single unix variable. How can i pass the values from 2... (2 Replies)
Discussion started by: rafa_fed2
2 Replies

5. Shell Programming and Scripting

Passing values from awk to shell variable

I am writing a script where I need awk to test if two columns are the same and shell to do something if they are or are not. Here is the code I'm working with: @ test = 0 ... test = `awk '{if($1!=$2) print 1; else print 0}' time_test.tmp` #time_test.tmp holds two values separated by a space... (3 Replies)
Discussion started by: Malavin
3 Replies

6. Shell Programming and Scripting

Passing awk variable argument to a script which is being called inside awk

consider the script below sh /opt/hqe/hqapi1-client-5.0.0/bin/hqapi.sh alert list --host=localhost --port=7443 --user=hqadmin --password=hqadmin --secure=true >/tmp/alerts.xml awk -F'' '{for(i=1;i<=NF;i++){ if($i=="Alert id") { if(id!="") if(dt!=""){ cmd="sh someScript.sh... (2 Replies)
Discussion started by: vivek d r
2 Replies

7. UNIX for Dummies Questions & Answers

Passing of variable values to remote server

Hi, My script will take 3 i/p's from user. Now i need to pass these 3 values to remote server. Please find my code. while do echo " To which server you want to connect ? " echo " 1. server1 \n" echo " 2. server2 \n" read opt_server if then echo "enter the... (2 Replies)
Discussion started by: sree143reddy
2 Replies

8. Shell Programming and Scripting

Trouble with passing Variable from bash to awk gsub command

Would really appreciate it if someone could point out my mistake in this line of code, i've been staring blankly at it trying everything i can think of some time now and coming up with nothing. #!/bin/bash echo "Enter Username" read Username awk -F: -v var=${Username} '/^var:/... (9 Replies)
Discussion started by: Nostyx
9 Replies

9. UNIX for Dummies Questions & Answers

scripting: multiple values from file passing to command

one of my colleagues has this question. he has a command, C_CMD which accepts 4 variables, $1 $2 $3 $4 he wants to load up a file with multiple rows, one row per set of variables and then iteratively execute the command based on the content of the file. example: at the command line you'd... (5 Replies)
Discussion started by: LisaS
5 Replies

10. Shell Programming and Scripting

Passing values out awk.

found that passing (input) values to awk, all work well. For example: errpt | awk 'BEGIN { errore=0 } substr($2,1,4) /'ParamData'/ { .... } ' ParamData=`date +"%m%d"` Now I wish to obtain (output) a value. Using this method is it possible to re-write ParamData, for example? Thanks in... (3 Replies)
Discussion started by: gio123bg
3 Replies
Login or Register to Ask a Question