awk without quotes


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting awk without quotes
# 1  
Old 08-30-2012
Java awk without quotes

I want to execute awk command without quotes.

Code:
who am i | awk {'print $2'}

above code should be something like:

Code:
who am i | awk {print $2}

Why such weird requirement?
Im assigning command to a variable, hence i need to escape the quotes.
e.g:
Code:
x='who am i | awk {\'print $2\'}'

I want to avoid these escape character such that the code looks neat.

Thanks in advance...
# 2  
Old 08-30-2012
you probably should try this way

Code:
x=`who am i | awk '{print $2}`

# 3  
Old 08-30-2012
Hi

Code:
$ cat file
who am i | awk '{print $2}'

Code:
$ read x < file

Code:
$ echo $x
who am i | awk '{print $2}'

Guru.
# 4  
Old 08-30-2012
chidori: sorry I forgot to mention the condition.
I cannot use back ticks. Only single quotes are allowed

---------- Post updated at 12:32 PM ---------- Previous update was at 11:36 AM ----------

guruprasadpr: Your idea will work, but im looking for a way to avoid quotes in awk command
# 5  
Old 08-30-2012
If you use anything less strict than single quotes (double quote or no quote), you will have to escape the dollar sign, otherwise the shell will substitute it.
E.g.:

Code:
$ x="whomi | awk '{print \$2}'"
$ echo $x
whomi | awk '{print $2}'

# 6  
Old 08-30-2012
Quote:
Originally Posted by Arun_Linux
chidori: sorry I forgot to mention the condition.
I cannot use back ticks. Only single quotes are allowed
Why?
# 7  
Old 08-30-2012
im implementing it in python script. In python, I suppose back ticks cant be used to assign a value to variable

Here is the sample code in python.

Code:
output = command('who am i | awk \'{print($1)}\'')

Above command works fine. But I just dont want to use single quotes in awk statement such that i can avoid the usage of escape character \ and my command looks pretty neat.

Last edited by Arun_Linux; 08-30-2012 at 10:41 AM..
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

awk -File contain double quotes

Hi ALL, file data like : test.csv a,b,"c,d" my awk version is 4.0.2 ,if i am using the below code is working fine. awk -vFPAT='(*)|("+")' -vOFS="," '{print $3}' test.csv if the awk version is 3.1.7 is not working . Could you please help me on this one. output should be : "c,d" (6 Replies)
Discussion started by: bmk123
6 Replies

2. UNIX for Beginners Questions & Answers

Please explain the use of quotes in awk command in below example-

Example: `abc.ksh | grep '^GLIS'| awk -F' ' '{print \$1}'`; (3 Replies)
Discussion started by: Tanu
3 Replies

3. Shell Programming and Scripting

Using quotes in awk

Hello, i had a problem running a script , and after investigation found its all to do with the quotes: cat file1 line1 val1 val2 line2 val1 val2 line3 val1 val2 awk 'BEGIN {RS="\n\n"; FS="\n";} {print $1 $2}' file1 This gives me the wrong output: (5 Replies)
Discussion started by: andy391791
5 Replies

4. Shell Programming and Scripting

awk - Print where value is in quotes

Hi All, I have input data like follows: "1234"|"ABC" "1234"|"CBA" "1222"|"ZZZ" I am trying to awk print all records where Col1 = "1234". Below is the code I have so far: Var1=1 Var2=1234 awk -F "|" "$ ${Var1} == "\"${Var2}\"" { print; }' inputfile However when the AWK... (2 Replies)
Discussion started by: RichZR
2 Replies

5. Shell Programming and Scripting

awk problem with quotes

can someone help me with this. i keep getting errors: var1="MaxClients" var2="java|could not.*problem found|panic() failure seen|aborting " awk 'NR>=1&&NR<=10 && /'${var1}'/ && !/'${var2}'/ {++c}c==3{o=$0 RS $0 RS $0; print o; c=0}' log when i run the above, i keep getting: awk:... (3 Replies)
Discussion started by: SkySmart
3 Replies

6. UNIX for Dummies Questions & Answers

Help populating double quotes using awk

Want to populate double quotes for each filed using awk: Input: cat file.txt => "1-23-test_test1-test2" Required output : "1-23-test_test1-test2"|"#GT_properties_xyz" Was trying the below command on solaris 9 machine : awk -F"|" '{print $1"|""#GT_properties_xyz"}' file.txt ... (8 Replies)
Discussion started by: rajachandhok
8 Replies

7. Shell Programming and Scripting

Using double quotes in awk

Hi I read somewhere that when using double quotes in awk; variables gets expanded else it doesn't. So I tried to use the double quotes inside an awk statement as below: from_instance_trans=`awk "/INPUT =\"$frm_inst\"/,/<\/TRANSFORMATION>/" $xml_object | grep -w "<TRANSFIELD" | awk... (9 Replies)
Discussion started by: dips_ag
9 Replies

8. UNIX for Advanced & Expert Users

awk function in handling quotes

Hi all, I have input lines like below empno,ename,sal,description ---------------------------- 311,"jone,abc",2000,manager 301,david,200,"president,ac" I need to sum the salary of them i.e. 2000+200 anything suggested Thanks, Shahnaz. Use code tags. (5 Replies)
Discussion started by: shahnazurs
5 Replies

9. Shell Programming and Scripting

quotes using awk

i want to print the statement below using awk,but i am unable to get the quotes ("22345",1,"Thank you"); How can i do this (5 Replies)
Discussion started by: tomjones
5 Replies

10. Shell Programming and Scripting

problem with quotes in awk script

i have write this script: #!/usr/bin/gawk -f BEGIN { strins="/usr/bin/mysql --user=user --password=pass -h localhost -D admin_test -e 'INSERT INTO test (id, perc) VALUES ('aaa',0)'" system(strins) } the table test are so defined: id(varchar(10)), perc(int(10)) the error that i... (10 Replies)
Discussion started by: dogo21sob
10 Replies
Login or Register to Ask a Question