Unable to pass shell script variable to awk command in same shell script


Login or Register for Dates, Times and to Reply

 
Thread Tools Search this Thread
# 1  
Unable to pass shell script variable to awk command in same shell script

I have a shell script (.sh) and I want to pass a parameter value to the awk command but I am getting exception, please assist.

Code:
diff=$1$2.diff 
id=$2 new=new_$diff  
echo "My id is $1" 
echo "I want to  sync for user account $id"  
##awk command I am using is as below  
cat  $diff | awk -F'~' ''$2 == "$id"' {print $0}' > $new

I also tried below options but no success, please suggest.

Code:
awk -F'~' -v search=$id '$2 == "search" {print $0} file'  nayaka2almadm1.diff > $new
cat $diff | awk -v "search=$id" -F'~'  '$2 == "search" {print $0}' > $new
cat $diff | awk -F'~' -v  search="$id" '$2 ~ "^\"search {print $0}' > $new
awk -v  search="$id" file="$diff" | awk -F'~' '$2 == search {print $0} file'  > $new

Moderator's Comments:
Mod Comment Moved thread to a technical forum. Set user "Read Only" because repeatedly posts in non-technical forum, not following forum directions.

Last edited by Ashunayak; 01-27-2014 at 01:56 PM..
# 2  
Code:
awk -F'~' -v search="$id" '$2 == search {print $0} file'  nayaka2almadm1.diff > $new

# 3  
Do not post technical questions in non-technical forums.

This is the second time today, so you have been set to "Read Only", sorry.

Follow forum rules, directions and guidelines.
Login or Register for Dates, Times and to Reply

Previous Thread | Next Thread
Thread Tools Search this Thread
Search this Thread:
Advanced Search

Test Your Knowledge in Computers #571
Difficulty: Medium
A simple units bug in the Mars Climate Orbiter caused an error which resulted in loses of over $125M USD in 1999.
True or False?

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Shell script to pass the config file lines as variable on the respective called function on a script

I want to make a config file which contain all the paths. i want to read the config file line by line and pass as an argument on my below function. Replace all the path with reading config path line by line and pass in respective functions. how can i achieve that? Kindly guide. ... (6 Replies)
Discussion started by: sadique.manzar
6 Replies

2. 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

3. Shell Programming and Scripting

Unable to pass value from .Shell script to .SQL file

Hi All, I am new to shell script. I am trying to pass value from .sh file to .sql file . But I am able to run the .sql file from .sh file with values in sql file. But I am unable to pass the values from .sh file. can some one please help to resolve this. here is my .sh file s1.sh ... (4 Replies)
Discussion started by: reddy298599
4 Replies

4. Shell Programming and Scripting

Unable to pass send command in shell script

I am trying to automate a testcase . I am installing some software and it waits for user input after displaying "Do you want to continue ? " I am trying to do this in shell scripting. #!/bin/bash #!/usr/bin/expect -f /usr/bin/expect << EOF spawn apt-get install openjdk-7-jdk expect "*Do you... (1 Reply)
Discussion started by: Abdul Navaz
1 Replies

5. Post Here to Contact Site Administrators and Moderators

Unable to pass shell script parameter value to awk command in side the same script

Variable I have in my shell script diff=$1$2.diff id=$2 new=new_$diff echo "My id is $1" echo "I want to sync for user account $id" ##awk command I am using is as below cat $diff | awk -F'~' ''$2 == "$id"' {print $0}' > $new I could see value of $id is not passing to the awk... (0 Replies)
Discussion started by: Ashunayak
0 Replies

6. Shell Programming and Scripting

unable to pass value to user prompt from calling shell script

This is my script structure main script calls configure script which needs to be run as a different user and the configure script calls my application installation script. the application instruction script prompts the user for a directory which I need to pass from my main or configure script. ... (4 Replies)
Discussion started by: cmastays
4 Replies

7. Shell Programming and Scripting

pass variable from awk to shell script

Hello Experts, Actually I was searching for a solution here in this forum , but didn't get what exactly I want . Is this possible to do in awk ? I am trying to do some thing like below in ksh script . Upto my knowledge I can pass shell script to awk with "-v " option. But I... (3 Replies)
Discussion started by: user_prady
3 Replies

8. 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

9. UNIX for Dummies Questions & Answers

How to pass Shell script variable to awk

Hi, I have a shell script with an ambedded awk script. i need to pass a script variable to the awk script. Please help. Thanks in advance Himani (3 Replies)
Discussion started by: HIMANI
3 Replies

10. UNIX for Dummies Questions & Answers

How to Pass variable to shell Script

Hi , i am beginner to Unix, I have one small script which execute java programme,it has java command input output structure . Right now i have given Input output structure manually that is on same directory, now how can i pass that by commandline #!/bin/sh java Classjava input.txt... (5 Replies)
Discussion started by: sam70
5 Replies

Featured Tech Videos