problem using awk


Login or Register for Dates, Times and to Reply

 
Thread Tools Search this Thread
# 1  
problem using awk

Hi, Anyone know why i get this error?

+ awk -F, '{if($5=="x" && $6=="y" && $10=="z")print $0}' file.data
awk: syntax error near line 1
awk: bailing out near line 1

This is the output from a shell script that can be resumed like...

set -x
fich_dat=file.data
variable1=x
variable2=y
variable3=z
awk -F, \''{if($5=='\"$variable1\"' && $6=='\"$variable2\"' && $10=='\"$variable3\"')print $0}'\' $fich_dat



The most strange is that if i copy paste:
awk -F, '{if($5=="x" && $6=="y" && $10=="z")print $0}' file.data
in the unix console, it works.

The UNIX system is:
Sun Microsystems Inc. SunOS 5.9
# 2  
Try this syntax :
Code:
set -x
fich_dat=file.data
variable1=x
variable2=y
variable3=z
awk -F, -v V1="$variable1" -v V2="$variable2" -v V3="$variable3" \
'{if($5==V1 && $6==V2 && $10==V3)print $0}' $fich_dat

In case of error, try to use nawk instead of awk

Jean-Pierre.
# 3  
merci! vous Ítes une machine!

This code works:

nawk -F, -v V1="$variable1" -v V2="$variable2" -v V3="$variable3" '{if($5==V1 && $6==V2 && $10==V3)print $0}' $fich_dat
# 4  
or a bit more terse:
Code:
nawk -F, -v V1="$variable1" -v V2="$variable2" -v V3="$variable3" '$5==V1 && $6==V2 && $10==V3' $fich_dat

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 #950
Difficulty: Medium
The first academic work on the theory of self-replicating computer programs was done in 1949 by Alan Turing.
True or False?

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

awk problem

i have an email list in file.txt with comma separated line1 - FIELD1,pippo@gmail.com,darth@gmail.com line2 - FIELD2,pippo@gmail.com,darth@gmail.com,sampei@gmail.com output=(awk -F ',' -v var="$awkvar" '$1==var {print $2,$3,$4}' spreadsheet.txt)but awk delete some letters at the... (8 Replies)
Discussion started by: pasaico
8 Replies

2. Shell Programming and Scripting

Problem with sub in awk

Hello, I am trying to run the following code: awk '{if( NR>=10 && NR<=2000 ) sub($0,0)}1' infile > outfile in this data, to turn every line in a 0: 2.735369106580736E-002 6.959182059322828E-002 4.932889567426600E-001 1.189073666992422E+000 1.363209410266462E+000 ... (3 Replies)
Discussion started by: rogeriog.em
3 Replies

3. Shell Programming and Scripting

awk problem - combining awk statements

i have a datafile that has several lines that look like this: 2,dataflow,Sun Mar 17 16:50:01 2013,1363539001,2990,excelsheet,660,mortar,660,4 using the following command: awk -F, '{$3=strftime("%a %b %d %T %Y,%s",$3)}1' OFS=, $DATAFILE | egrep -v "\-OLDISSUES," | ${AWK} "/${MONTH} ${DAY}... (7 Replies)
Discussion started by: SkySmart
7 Replies

4. Shell Programming and Scripting

AWK Problem?

Consider this simple use of awk in a shell script EJB_USER=`awk -F= '/enrole.appServer.ejbuser.principal/ {print $2}' $ITIM_HOME/data/enRole.properties` In the file enRole.properties there is a line enrole.appServer.ejbuser.principal=itimadmin But when I run the shell script and echo... (6 Replies)
Discussion started by: datkan
6 Replies

5. AIX

AWK Problem?

Consider this simple use of awk in a shell script EJB_USER=`awk -F= '/enrole.appServer.ejbuser.principal/ {print $2}' $ITIM_HOME/data/enRole.properties` In the file enRole.properties there is a line enrole.appServer.ejbuser.principal=itimadmin But when I run the shell script and echo... (1 Reply)
Discussion started by: datkan
1 Replies

6. Shell Programming and Scripting

Problem with awk awk: program limit exceeded: sprintf buffer size=1020

Hi I have many problems with a script. I have a script that formats a text file but always prints the same error when i try to execute it The code is that: { if (NF==17){ print $0 }else{ fields=NF; all=$0; while... (2 Replies)
Discussion started by: fate
2 Replies

7. Shell Programming and Scripting

AWK Problem

I need help!!! I have a document with a description of n languages and I need to get only the name of every language that is descripted. and i need to get a list witH: ALGEBRAICA ALGOL 58 ALGOL60 I tried with awk "/*-/ {print $1} but i dont get the result that i want, please help me =D (5 Replies)
Discussion started by: PamPam
5 Replies

8. Shell Programming and Scripting

Awk problem: How to express the single quote(') by using awk print function

Actually I got a list of file end with *.txt I want to use the same command apply to all the *.txt Thus I try to find out the fastest way to write those same command in a script and then want to let them run automatics. For example: I got the file below: file1.txt file2.txt file3.txt... (4 Replies)
Discussion started by: patrick87
4 Replies

9. Shell Programming and Scripting

awk problem

I want to assign the file name under my dir and store into variable fileName here is my for loop but awk seems doesn't work numberFile=`ls -l $dir | wc -l` for i in $numberFiles do fileName=` ls -l | awk `{print $8}`` blablabla done thanks for helping (4 Replies)
Discussion started by: cryogen
4 Replies

10. Shell Programming and Scripting

AWK Problem Need Help!

I have a problem that I have not be able to get solved. First of all the script I am writing is for a Windows server. I am trying to write a script that will connect to a ISCSI SAN and locate the last Snapshot for that server and mount it for a backup. In order to capture the screens I have been... (14 Replies)
Discussion started by: netmedic
14 Replies

Featured Tech Videos