Cannot resolve $var in awk


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Cannot resolve $var in awk
# 1  
Old 06-24-2013
Cannot resolve $var in awk

My script
----------
Code:
for i in `cat n`;do
export k=`echo "CSN: "$i`       //combining CSN: and value from n
echo "$k"
awk ''{print "CSN: "$0;}'{_=29}_&&_--' file1|tail -1 >> file2
done

In the above script i cannot able to resolve $k in awk command
file n contains
------------
0000
1111
2222
3333
4444
6666

I am trying to append CSN: 0000 and search it in the file1 and
display the 29th line from the searched pattern

Last edited by jim mcnamara; 06-25-2013 at 12:10 AM.. Reason: dupilcate thread - closed
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Cannot resolve $variable in awk

My script ---------- for i in `cat n`;do export k=`echo "CSN: "$i` //combining CSN: and value from n echo "$k" awk ''{print "CSN: "$0;}'{_=29}_&&_--' file1|tail -1 >> file2 done In the above script i cannot able to resolve $k in awk command file n contains ------------ 0000 1111 2222... (2 Replies)
Discussion started by: Mohana29_1988
2 Replies

2. Shell Programming and Scripting

awk: compose regex in variable and then use its contents like $0 ~ var

A question to the awk pundits: I was thinking about composing a regex in a variable and then use its contents like $0 ~ var instead of $0 ~ /r/. Sort of indirection. Did someone run into this? Is it possible at all? (3 Replies)
Discussion started by: RudiC
3 Replies

3. Shell Programming and Scripting

[awk] split file1 and save it as var from file2

I have 2 files: file_1: file_2: expected result: name file: "artV1" "artV2" etc. I have: but why don;t work save to file 'out'?? (3 Replies)
Discussion started by: ffresz
3 Replies

4. Shell Programming and Scripting

awk - sub() function and NR==var

Why does this work: awk 'NR==3 sub(FS $NF,x)' inputfile But not this: var=3 awk -v i=$var 'NR==i sub(FS $NF,x)' inputfile How would you do the same thing as the first line of code, but with a variable? (2 Replies)
Discussion started by: locoroco
2 Replies

5. Shell Programming and Scripting

The awk subtraction giving exponential values.Please help resolve it

Hi friends, I have a file list1 which has these 2 columns like 616449 0 434453 1 2151083 0 2226536 0 2132382 0 2136814 0 I have to put the result of col1 -col2 into another file list2 linewise. e.g. It gives the below result if use the below code: awk '{ print $1 - $2 }' list1 >... (2 Replies)
Discussion started by: kunwar
2 Replies

6. Solaris

diff b/w /var/log/syslog and /var/adm/messages

hi sirs can u tell the difference between /var/log/syslogs and /var/adm/messages in my working place i am having two servers. in one servers messages file is empty and syslog file is going on increasing.. and in another servers message file is going on increasing but syslog file is... (2 Replies)
Discussion started by: tv.praveenkumar
2 Replies

7. Shell Programming and Scripting

Does awk ever resolve params ?..

Hi, Does awk ever resolve params in the search pattern?.. The following awk doesnt know how to resolve ${tables}$ inside a loop. k=`awk '/${tables}$/ ${graph}` The search pattern has ${tables}$ and I am narrowing down my search with a $ at the end of string. So...this leaves me with a... (13 Replies)
Discussion started by: anduzzi
13 Replies

8. UNIX for Dummies Questions & Answers

Can any good awk'er resolve this issue?

awk -F^ '{ if ((($1 != "M") && ($5 != "2")) || (($1 != "S") && ($5 != "7"))) print $0}' welcome > welcome1 The "&&" and "||" in the above command is not working with awk. When I run the above command, the same content of welcome is copied to welcome1 without any difference. Your reply is... (12 Replies)
Discussion started by: karthickrn
12 Replies

9. Shell Programming and Scripting

use var in gsub of awk

Hi all, This problem has cost me half a day, and i still do not know how to do. Any help will be appreciated. Thanks advance. I want to use a variable as the first parameters of gsub function of awk. Example: { ... arri]=gsub(i,tolower(i),$1) (which should be ambraced by //) ... } (1 Reply)
Discussion started by: summer_cherry
1 Replies

10. Shell Programming and Scripting

Var substitution in awk - not working as expected

countA=`awk '/X/''{print substr($0,38,1)}' fName | wc -l` countB=`wc -l fName | awk '{print int($1)}'` echo > temp ratio=`awk -va=$countA -vc=$countB '{printf "%.4f", a/c}' temp` After running script for above I am getting an error as : awk: 0602-533 Cannot find or open file -vc=25. The... (3 Replies)
Discussion started by: videsh77
3 Replies
Login or Register to Ask a Question
escape(1)							Mail Avenger 0.8.3							 escape(1)

NAME
escape - escape shell special characters in a string SYNOPSIS
escape string DESCRIPTION
escape prepends a "" character to all shell special characters in string, making it safe to compose a shell command with the result. EXAMPLES
The following is a contrived example showing how one can unintentionally end up executing the contents of a string: $ var='; echo gotcha!' $ eval echo hi $var hi gotcha! $ Using escape, one can avoid executing the contents of $var: $ eval echo hi `escape "$var"` hi ; echo gotcha! $ A less contrived example is passing arguments to Mail Avenger bodytest commands containing possibly unsafe environment variables. For example, you might write a hypothetical reject_bcc script to reject mail not explicitly addressed to the recipient: #!/bin/sh formail -x to -x cc -x resent-to -x resent-cc | fgrep "$1" > /dev/null && exit 0 echo "<$1>.. address does not accept blind carbon copies" exit 100 To invoke this script, passing it the recipient address as an argument, you would need to put the following in your Mail Avenger rcpt script: bodytest reject_bcc `escape "$RECIPIENT"` SEE ALSO
avenger(1), The Mail Avenger home page: <http://www.mailavenger.org/>. BUGS
escape is designed for the Bourne shell, which is what Mail Avenger scripts use. escape might or might not work with other shells. AUTHOR
David Mazieres Mail Avenger 0.8.3 2012-04-05 escape(1)