Sponsored Content
Top Forums Shell Programming and Scripting How to pass IF condition via shell varibale in awk? Post 302977772 by anillambait on Friday 22nd of July 2016 03:51:36 AM
Old 07-22-2016
How to pass IF condition via shell varibale in awk?

Hello,

I have one query regarding passing IF condition shell variable inside awk. Here is the case-

File content of keydefn.exp
Code:
201~2~LM Limit 02-current value~Limit 02    ~Limit02~Current~Value  ~N~Y~S~0~9999999
201~3~LM Limit 03-current value~Limit 03~Limit03~Current~Value~N~Y~S~-9999999~9999999

Case 1:
Code:
awk 'BEGIN{IGNORECASE=1;FS="~"}; { if ($2=="2") { print $0}}' keydefn.exp  ==> This is working fine!

Output:
Code:
201~2~LM Limit 02-current value~Limit 02    ~Limit02~Current~Value  ~N~Y~S~0~9999999


Case 2:
But when we move the IF condition in some variable like con='$2 == "2"' then it's not working

Code:
awk -v cond="$con" 'BEGIN{IGNORECASE=1;FS="~"}; { if (cond) { print $0}}' keydefn.exp  ==> This is not working

Output:
Code:
201~2~LM Limit 02-current value~Limit 02    ~Limit02~Current~Value  ~N~Y~S~0~9999999
201~3~LM Limit 03-current value~Limit 03~Limit03~Current~Value~N~Y~S~-9999999~9999999

Please suggest the reason!

Last edited by Scrutinizer; 07-22-2016 at 05:30 AM.. Reason: code tags
 

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Is it possible to pass variable from awk to shell script

Hello experts, can I return a value from gawk to a shell script ? My script as follows, #Here I want the num value to shell script so that I can use later gawk ' { split($0,num,","); print num }' gawk -v no=$number '{print no}' file1 ... (3 Replies)
Discussion started by: user_prady
3 Replies

2. Shell Programming and Scripting

Pass array variabel to awk from shell

Hi I need to pass an array to Awk script from Shell. Can you please tell how to do it? How to pass this array add_ct_arr to an awk script or access it in awk? i=1 while ; do add_ct_arr=$(echo ${adda_count} | awk -v i=$i -F" " '{print $i;}') echo ${add_ct_arr} ... (1 Reply)
Discussion started by: appsguy616
1 Replies

3. Shell Programming and Scripting

How to pass values between awk and shell scripts

I know that we can call system command to execute shell script in awk. but it does not return the result of the command executed , but only returns the value of the command executoin status ( 1/0 --> failure / success). Could anyone let me know how to solve this problem. (9 Replies)
Discussion started by: rajnikanth.1912
9 Replies

4. Shell Programming and Scripting

How to pass shell variables to awk's pattern?

How would I get folders owned by specific users.. I want to pass users as a shell variable to awk. drwxr-x--x 3 user1 allusers 512 Oct 14 2006 946157019/ drwxr-x--x 3 user2 allusers 512 Mar 9 2008 94825883/ drwxr-x--x 3 user3 allusers 512 Mar 9 2008 948390501/ ... (3 Replies)
Discussion started by: kchinnam
3 Replies

5. UNIX for Dummies Questions & Answers

How to pass a variable from shell to awk

I know this topic has been dealt with previously, but the solutions I've seen don't work for me apparently. I need to pass a variable defined in the shell to one in awk: $ echo $var1 3 $ cat aaa aaa 1 bbb 2 ccc 3 ddd 4 eee 5I've tried this, without success: $ awk... (2 Replies)
Discussion started by: metaltree
2 Replies

6. Shell Programming and Scripting

pass shell parameters to awk does not work

Why does this work for myfile in `find . -name "R*VER" -mtime +1` do SHELLVAR=`grep ^err $myfile || echo "No error"` ECHO $SHELLVAR done and outputs No error err ->BIST Login Fail 3922 err No error err ->IR Remote Key 1 3310 err But... (2 Replies)
Discussion started by: alan
2 Replies

7. Shell Programming and Scripting

Pass awk array variable to shell

Hi, all suppose I have following myfile (delimited by tab) aa bb cc dd ee ffand I have following awk command: awk 'BEGIN{FS="\t"}{AwkArrayVar_1=$1;AwkArrayVar_2=$2};END{for(i=0; i<NR; i++) print i, AwkArrayVar_1, AwkArrayVar_2,}' myfileMy question is: how can I assign the awk array... (7 Replies)
Discussion started by: littlewenwen
7 Replies

8. UNIX for Dummies Questions & Answers

Pass shell Variable to awk

Hello, May i please know how do i pass the shell variable to awk expression in the below script. It is returning null #!/bin/bash UNINUM=720922 UNINUM_DESC=`awk -F'|' -v UNINUM=$2 '/UNINUM/ {print $4}' datafile` echo $UNINUM_DESC datafile 4|First|720194|asdasdad 4|First|720735|asdasdsa... (8 Replies)
Discussion started by: Ariean
8 Replies

9. Shell Programming and Scripting

Need to pass shell arguments into Nawk/awk

Hi, I am in critical need of help, Thanks a ton for your help. I need to know how to pass the shell argument into nawk code in AIX. so that my file gets passed into that awk script and it can execute it part. To be detail, i have more than 100 files and in those files a particular field... (6 Replies)
Discussion started by: Selva_2507
6 Replies

10. Shell Programming and Scripting

How to pass variable from awk script to shell?

Hi, Please need to print the Rej variable outsite the awk script which is given below...please advised how to achieve it. #!/bin/bash echo "Enter DMU Pipe delimited File name for the Feed to be validated" read DMU_File echo "Enter Pre-DMU File name for the Feed" read Predum_file ... (3 Replies)
Discussion started by: pelethangjam
3 Replies
softlimit(8)						      System Manager's Manual						      softlimit(8)

NAME
softlimit - runs another program with new resource limits. SYNOPSIS
softlimit [ opts ] child DESCRIPTION
opts is a series of getopt-style options. child consists of one or more arguments. softlimit sets soft resource limits as specified by opts. It then runs child. OPTIONS
In each of the following opts, n may be =, indicating that the soft limit should be set equal to the hard limit. opts controlling memory use: -m n Same as -d n -s n -l n -a n. -d n Limit the data segment per process to n bytes. -s n Limit the stack segment per process to n bytes. -l n Limit the locked physical pages per process to n bytes. This option has no effect on some operating systems. -a n Limit the total of all segments per process to n bytes. This option has no effect on some operating systems. -o n Limit the number of open file descriptors per process to n. This option has no effect on some operating systems. -p n Limit the number of processes per uid to n. opts controlling file sizes: -f n Limit output file sizes to n bytes. -c n Limit core file sizes to n bytes. Efficiency opts: -r n Limit the resident set size to n bytes. This limit is not enforced unless physical memory is full. -t n Limit the CPU time to n seconds. This limit is not enforced except that the process receives a SIGXCPU signal after n seconds. SEE ALSO
supervise(8), svc(8), svok(8), svstat(8), svscanboot(8), svscan(8), readproctitle(8), fghack(8), pgrphack(8), multilog(8), tai64n(8), tai64nlocal(8), setuidgid(8), envuidgid(8), envdir(8), setlock(8) http://cr.yp.to/daemontools.html softlimit(8)
All times are GMT -4. The time now is 11:46 AM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy