awk problem with quotes


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting awk problem with quotes
# 1  
Old 02-20-2013
awk problem with quotes

can someone help me with this. i keep getting errors:

Code:
var1="MaxClients"
var2="java|could not.*problem found|panic() failure seen|aborting [ERROR]"

Code:
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:

Code:
awk: NR>=1&&NR<=10 && /MaxClients/ && !/java|could
awk:                                    ^ unterminated regexp


if anybody is able to fix the above, i'm also interested in how i can modify it so it gives the count of lines returned, instead of showing the lines. something like:

Code:
awk 'NR>=1&&NR<=10 && /'${var1}'/ && !/'${var2}'/ {++c}c==3{o=$0 RS $0 RS $0; print o; c=0}' log
4


Last edited by SkySmart; 02-20-2013 at 03:41 PM..
# 2  
Old 02-20-2013
Code:
awk -v var1="$var1" -v var2="$var2" 'NR>=1&&NR<=10 && $0 ~ var1 && $0 !~ var2 {...}'

PS: I am not sure what the test "NR>=1" is expected to do.
# 3  
Old 02-20-2013
NR>=1 is not need since you always start at record #1
# 4  
Old 02-20-2013
More a shell quoting question:
Code:
awk 'NR>=1&&NR<=10 && /'"${var1}"'/ && !/'"${var2}"'/ {++c}c==3{o=$0 RS $0 RS $0; print o; c=0}' log

When you leave the shelter of the ', at least wear a " so your spaces do not confuse the shell!
This User Gave Thanks to DGPickett For This Post:
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

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

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

3. Shell Programming and Scripting

awk without quotes

I want to execute awk command without quotes. who am i | awk {'print $2'} above code should be something like: 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: x='who am i | awk {\'print $2\'}' I want... (11 Replies)
Discussion started by: Arun_Linux
11 Replies

4. Shell Programming and Scripting

Having a terrible problem with quotes/single quotes!

Hello. I'm trying to write a bash script that uses GNU screen and have hit a brick wall that has cost me many hours... (I'm sure it has something to do with quoting/globbing, which is why I post it here) I can make a script that does the following just fine: test.sh: #!/bin/bash # make... (2 Replies)
Discussion started by: jondecker76
2 Replies

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

6. Shell Programming and Scripting

problem with echo inserting single quotes

Consider the following script: #!/bin/bash exclude='Archive PST,SystemState' IFS=$"," rsyncExclusions=$(for exclude in ${exclude}; do echo -n -e --exclude=\"${exclude}\"\ ; done) unset IFS echo rsync $rsyncExclusions test rsync -avh --delete --delete-excluded "$rsyncExclusions"... (7 Replies)
Discussion started by: jelloir
7 Replies

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

8. Shell Programming and Scripting

Problem renaming a file with single quotes

Hi, I am trying to create a script which validates the incoming source files. The script has File name Pattern as Argument. The First part of the script validates if there are any files available if then echo "\n Files are available to process \n" else echo "\n File does not... (9 Replies)
Discussion started by: dsshishya
9 Replies

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

10. Shell Programming and Scripting

problem with single quotes in a string and findbug

I'm having trouble manipulating a string that contains single quotes (') in it. I'm writing a ksh script to parse in a few queries from a config file, such as this: findbug \(\(Project 'in' "Deployment,HDRCI,LHS,LSS,WUCI" '&&' Status 'in' "N" '&&' New_on 'lessthan' "070107" \)\) '&&' \(Class... (9 Replies)
Discussion started by: bob122480
9 Replies
Login or Register to Ask a Question