awk code does not receive input


 
Thread Tools Search this Thread
Top Forums UNIX for Dummies Questions & Answers awk code does not receive input
# 1  
Old 11-09-2013
awk code does not receive input

I'm just starting to understand how awk works and yet this is really driving me crazy. I can't guarantee the rest is correct but I know the input is not being received via the ' $ ' sign. Can anyone tell me what's wrong with my code??
Code:
{
        EAS_ACC=$2;
        NOR_ACC=$3;

        if(((EASTING - 200 <= EAS_ACC) || (EASTING + 200 >= EAS_ACC)) && ((NORTHING - 200 <= NOR_ACC) || (NORTHING + 200 >= NOR_ACC)))
        {
                print sqrt((EAS_ACC - EASTING) * (EAS_ACC - EASTING) + (NOR_ACC - NORTHING) * (NOR_ACC - NORTHING));
                print " ";
                print ($2 $3 $4 $5);
                print " ";
                print $10;
                print " ";
                print $11;
        }
}


Last edited by Scott; 11-10-2013 at 02:02 AM.. Reason: Please use code tags
# 2  
Old 11-10-2013
Quote:
Originally Posted by o2tha1
I'm just starting to understand how awk works and yet this is really driving me crazy. I can't guarantee the rest is correct but I know the input is not being received via the ' $ ' sign. Can anyone tell me what's wrong with my code??
Code:
{
        EAS_ACC=$2;
        NOR_ACC=$3;

        if(((EASTING - 200 <= EAS_ACC) || (EASTING + 200 >=  EAS_ACC)) && ((NORTHING - 200 <= NOR_ACC) || (NORTHING + 200  >= NOR_ACC)))
        {
                print sqrt((EAS_ACC - EASTING) * (EAS_ACC - EASTING) + (NOR_ACC - NORTHING) * (NOR_ACC - NORTHING));
                print " ";
                print ($2 $3 $4 $5);
                print " ";
                print $10;
                print " ";
                print $11;
        }
}

Without knowing $2 and $3 we can't help and where did you define NORTHING and EASTING ?

If you show input and expected output, we can help you.
# 3  
Old 11-10-2013
awk takes a file as input.
The $1 $2 are set from its fields.
Give the file name as parameter.
Addional parameters can set awk variables.
For example, assuming your awk code is saved in the file awkscript
Code:
awk -v EASTING=1 -v NORTHING=2 -f awkscript inputfile


Last edited by MadeInGermany; 11-11-2013 at 05:40 AM.. Reason: -f not -F
# 4  
Old 11-10-2013
Sorry about being ambiguous. This is the input:

Code:
cat DfTRoadSafety_Accidents_2012.csv | awk -v
EASTING=454590.00 -v NORTHING=339970.00 -v RADIUS=200 -f
nearby-accidents.awk

the expected output is:

167.598 454707 340090 -1.187115 52.955382 19/04/2012 5
108.462 454548 340070 -1.189485 52.955219 10/07/2012 3
164.77 454705 340088 -1.187145 52.955364 24/12/2012 2

Unfortunately I don't seem to be able to upload the file but I've added a print screen for a general idea of what it looks like.

My main question is how do I add the values of specific columns (e.g. 2 and 3) into EAS_ACC and NOR_ACC? That's what I think I'm doing wrong.
awk code does not receive input-ecran-de-webpng

Last edited by o2tha1; 11-10-2013 at 08:41 AM..
# 5  
Old 11-10-2013
Please use code tag as required by forum rules!
And, you can try to post some lines of your input file between code tags...

Did you try to set the field separator to ","? Like awk -F","...
# 6  
Old 11-10-2013
I haven't tried that because I'm not really clear on how the .csv files separate their columns.. so can I add that to the .awk file or does it have to be in the command line?
# 7  
Old 11-10-2013
You can have like I posted in the command line, or you can run it in the BEGIN section of the script file.
 
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Red Hat

Looking for C code for MQ server to sed/receive messages

I am working on C program to connect to MQ websphere server send/receive messages. Can somebody give me examples of such program? Thanks for contribution (0 Replies)
Discussion started by: digioleg54
0 Replies

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

3. Shell Programming and Scripting

User input in perl code

Hello friends . I am newbie to perl scripting but still managed to write a code but i am stuck at a place where i need help . Below is the code and can someone help me in taking user input for changing the font size for a html table .Thank you in advance #!/bin/ksh echo " Enter the Directory... (4 Replies)
Discussion started by: ajayram_arya
4 Replies

4. Shell Programming and Scripting

Parse input -AWK

Input File Defined configuration: cfg: CLL_DCC_Fabric_A BTS00P21; BAU_AP00P01QC; BAU_LGSCNJP02; BAU_TS00P20; BAU_DSMSM14; BAU_HT00P02; BAU_DSMSM13; BAU_HT00P01; cfg: CX0014_list BAU_TS00P20; BAU_NYP_PRODIAD1_CJ;... (5 Replies)
Discussion started by: greycells
5 Replies

5. Shell Programming and Scripting

Hard code the input of a script

Hi All, I have a script Abc . This is has only the privilege of execution. I cannot see the code. When I run the script "Abc" , It display set of name in an random order with a number 1.e 1 James 2 john 3 jack 4 neil 5 bob If my name is neil , I am expected to type 4 and press enter Now... (5 Replies)
Discussion started by: mailvkjain
5 Replies

6. Shell Programming and Scripting

AWK using two input files

Hi , i have two input files one is input.gz and another is ( input.txt) text file.in gz format input file each record contains 10 fields and corresponding header value is present in the text file as a single record i.e text file contains only 10 records which is header value,so output of the awk... (1 Reply)
Discussion started by: Ajoy
1 Replies

7. Shell Programming and Scripting

awk user input

Using the following I'm trying to print the user's response to the prompt Y / N but I get nothing other than the contents of $1? awk '{ printf($1 " ? (Y/N)") getline myresponse < "-" system("read myresponse") if (myresponse == "Y") { print $1... (17 Replies)
Discussion started by: gefa
17 Replies

8. Shell Programming and Scripting

2 input files for awk

Hi, i have 2 files like f1 and f2 f1: 1 Note: some times it will be cahnged to 2 and 3. f2: 1:20 2:30 4:50 6:70 8:90 3:20 1:30 1:40 output: 1:80 (sum of 1) (6 Replies)
Discussion started by: koti_rama
6 Replies

9. Shell Programming and Scripting

awk/input parameter

Hi, My script takes in one input parameter($1-email id) on the command line... The script contains something like this... awk '$1 == 400' abc.log >def.log mail -s subject $1 <def.log abc.log looks something like this... 300 222 330 123 445 400 098 890 727 663 How do i make the... (3 Replies)
Discussion started by: wannalearn
3 Replies

10. Shell Programming and Scripting

awk - input function

hello, im a newbie. how can i input data from keyboard? thanks. (3 Replies)
Discussion started by: Jariya
3 Replies
Login or Register to Ask a Question