print user variable input

Thread Tools Search this Thread
# 1  
print user variable input

this may be basic thing for everyone here, but i cant push awk to print the variable user input which is INS, please help.


printf '\n'
symdg list | grep $INS-clone | awk -v i=$INS '{ID=substr($4,9,4)}{print "Device Group: "$1,"at Array "ID,i}'

$ ./ patty

awk: syntax error near line 1
awk: bailing out near line 1

# 2  
try using nawk
# 3  
it worked, thanks! what would be difference / specific application wherein nawk is better than awk??
# 4  
Originally Posted by prodigy06
what would be difference / specific application wherein nawk is better than awk??
Are you using Solaris..?

As per my findings /usr/pkg4/bin/awk and nawk used in Solaris..

please do let me correct if i am wrong. not familiar with Solaris..Smilie

Last edited by pamu; 10-04-2012 at 06:10 AM..
# 5  
yes, its Solaris 9
# 6  
You could also put variables into awk the old-fashioned way:

awk '{...}' VARNAME="$VAR"

You really should be double-quoting all your shell variables, by the way.

Also, if you're using awk, you really don't need grep.

symdg list | awk '$0 ~ I"-clone" { ID=substr($4,9,4); print "Device Group: "$1,"at Array "ID,I}' I="$INS"

Last edited by Corona688; 10-04-2012 at 01:27 PM..

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

Test Your Knowledge in Science: Gadgets
Difficulty: Easy
The communication protocol NFC stands for Near-Field Control.
True or False?

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

User input and run awk using the input

I am trying to allow a user to enter in text and then store that text in a variable $gene to run in an awk command in which those values are used to run some calculations. I am getting syntax errors however, when I try. Thank you :). The awk runs great if it is a pre-defined file that is used,... (7 Replies)
Discussion started by: cmccabe
7 Replies

2. UNIX for Advanced & Expert Users

Passing variable as input & storing output in other variable

I have a below syntax its working fine... var12=$(ps -ef | grep apache | awk '{print $2,$4}') Im getting expected output as below: printf "%b\n" "${VAR12}" dell 123 dell 456 dell 457 Now I wrote a while loop.. the output of VAR12 should be passed as input parameters to while loop and results... (5 Replies)
Discussion started by: sam@sam
5 Replies

3. Shell Programming and Scripting

To print value for a $variable inside a $variable or file

Hi guys, I have a file "abc.dat" in below format: FILE_PATH||||$F_PATH TABLE_LIST||||a|b|c SYST_NM||||${SRC_SYST} Now I am trying to read the above file and want to print the value for above dollar variables F_PATH and SRC_SYST. The problem is it's reading the dollar variables as... (5 Replies)
Discussion started by: abcabc1103
5 Replies

4. Shell Programming and Scripting

XML variable for input in same input file

Dear All , i stuck in one problem executing xml .. i have input xml as <COMMAND name="ARRANGEMENT.WRITE" timestamp="0" so="initial"> <SVLOBJECT> <LONG name="CSP_PMNT_ID" val="-1"/> <MONEY name="CSP_CEILING" amount="0.0" currency="AUD"/> ... (6 Replies)
Discussion started by: arvindng
6 Replies

5. Shell Programming and Scripting

awk print variable then fields in variable

i have this variable: varT="1--2--3--5" i want to use awk to print field 3 from this variable. i dont want to do the "echo $varT". but here's my awk code: awk -v valA="$varT" "BEGIN {print valA}" this prints the entire line. i feel like i'm so close to getting what i want. i... (4 Replies)
Discussion started by: SkySmart
4 Replies

6. Shell Programming and Scripting

How to print column by getting user input.?

Hi.. I have data file.. and I could able to print using cat and awk like this cat filename awk '{print $1 "\t" $2 "\t" $3}' filenamebut I want to receive input from user like this echo -n " how many columns you want to display : " read abcsuppose if I give all, it should display all... (11 Replies)
Discussion started by: Akshay Hegde
11 Replies

7. Shell Programming and Scripting

Script interacts with user , based on user input it operates

i have a script which takes input from user, if user gives either Y/y then it should continue, else it should quit by displaying user cancelled. #!/bin/sh echo " Enter your choice to continue y/Y OR n/N to quit " read A if then echo " user requested to continue " ##some commands... (7 Replies)
Discussion started by: only4satish
7 Replies

8. Shell Programming and Scripting

How to get the user input recursively until the user provides valid input

Hi, echo "Enter file name of input file list along with absolute path : " read inputFileList if then for string in `cat inputFileList` do echo $string done else echo " file does not exist" fi From the above code, if the user enters a invalid file... (1 Reply)
Discussion started by: i.srini89
1 Replies

9. UNIX for Dummies Questions & Answers

Parsing name and phone as input and then print sub and marks out

I have a file like this : name phone id sub marks abc 2345 45 mat 90 bgt 6573 54 eng 89 ... .... .. ... .. ... .... .. ... .. Now i need to take in name and phone as input and then print sub and marks out, can u give me a sample code for this. P.S. If there are two of with same... (2 Replies)
Discussion started by: SasankaBITS
2 Replies

10. Shell Programming and Scripting

Force Input in User Defined Variable

In a line such as: echo -n "How many days back would you like to check? "; read days How can I ensure that the user has a.) entered a number between 1-30 (not 0 or 31+) and b.) has not just hit enter (ie set it to "") and if it's entered wrong, how do I start the if statement over? I... (10 Replies)
Discussion started by: earnstaf
10 Replies

Featured Tech Videos