Parameter value is not getting resolved


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Parameter value is not getting resolved
# 1  
Old 12-27-2016
Parameter value is not getting resolved

Hi,

I am using below command and its working fine:
Code:
$ zcat abc.dat.gz | awk -F\| 'NF==102{print NR,$0}'

but when I am using above command in script as below then temp_var2 is not getting resolved.
Code:
zcat "$1" | awk -F "$2" 'NF==$temp_var2{print NR,$0}'

Here, $1 and $2 are parameters which are passed while running script and temp_var2 I am creating inside which is getting assigned as numeric value.

Please help.

Last edited by Scrutinizer; 12-27-2016 at 04:36 PM.. Reason: code tags and formatting
# 2  
Old 12-27-2016
Shell variables are not expanded within single quotes.

Try something like this:
Code:
zcat "$1" | awk -F "$2" -v nrfields="$temp_var" 'NF==nrfields{print NR,$0}'

These 2 Users Gave Thanks to Scrutinizer For This Post:
# 3  
Old 12-27-2016
Thanks Scrutinizer!!
your command worked for me Smilie
Login or Register to Ask a Question

Previous Thread | Next Thread

8 More Discussions You Might Find Interesting

1. What is on Your Mind?

OUTAGE: Data Center Problem Resolved.

There was a problem with our data center today, creating a site outage (server unreachable). That problem has been resolved. Basically, it seems to have been a socially engineered denial-of-service attack against UNIX.com; which I stopped as soon as I found out what the problem was. Total... (2 Replies)
Discussion started by: Neo
2 Replies

2. What is on Your Mind?

Resolved: Issue in Server Data Center

Dear All, There was a problem in the data center data, which caused the server to be unreachable for about an hour. Server logs show the server did not crash or go down. Hence, I assume there was a networking issue at the data center. Still waiting for final word on what happened. ... (4 Replies)
Discussion started by: Neo
4 Replies

3. Solaris

[Resolved] Strange Issue with user logins

Ok got a strange one here. None of my user accounts are able to login into the system. When trying to ssh to the server i get the following. Could not chdir to home directory /home/<homedir>: Permission denied /bin/sh: Permission denied I checked the permissions on the home directory and even... (7 Replies)
Discussion started by: JoeDirte
7 Replies

4. Solaris

loghost could not be resolved

Hi friends, I have seen some really annoying error messages since I have installed Solaris, and solved a few of them, with your help. Now, another message pops up in the middle of my work, and says "loghost could not be resolved" Please help me with it. Here are the details for my solaris... (1 Reply)
Discussion started by: gabam
1 Replies

5. UNIX for Dummies Questions & Answers

Resolved: htpasswd issues (-b) on FreeBSD

I wrote a script to batch-create directories with .htaccess and .htpasswd files. I am using the following line to create the .htpasswd file: htpasswd -cb .htpasswd $USER $PASS However, I keep getting this message in return: Usage: htpasswd passwordfile username The -c flag creates a new... (1 Reply)
Discussion started by: Spetnik
1 Replies

6. Shell Programming and Scripting

Resolved: Building a string with a path in it

I know this is probably simple, but the brain cells that originally stored my shell scripting classes from 10+ years ago have long since been drowned in beer. I need to create a string (to append to a file) containing a path derived from the current path. Basically, I want to append "/something"... (3 Replies)
Discussion started by: Spetnik
3 Replies

7. Shell Programming and Scripting

How to set PATH using shell script [resolved]

Hi, Can anyone help me on how to set PATH using shell scripting.. Please find the shell script code here.... #!/bin/bash PATH = $PATH:/opt/app/oracle/product/10.2.0/bin export PATH echo $PATH exit When i execute this script i get the following error ./backup.sh: line 2: PATH:... (0 Replies)
Discussion started by: srinivasj
0 Replies

8. Shell Programming and Scripting

how do I make dynamic parameter names? Or get the value of a parameter evaluated twi

Say I write something like the following: var1=1 var2=2 for int in 1 2 do echo "\$var$int" done I want the output to be: 1 2 Instead I get something like: $var1 $var2 (2 Replies)
Discussion started by: Awanka
2 Replies
Login or Register to Ask a Question