How to take awk result out (piping to other program)?


 
Thread Tools Search this Thread
Homework and Emergencies Emergency UNIX and Linux Support How to take awk result out (piping to other program)?
# 8  
Old 01-05-2014
Quote:
Originally Posted by Akshay Hegde
Hi! all here is my code
which is working fine no errors but I want to know how to take result and input to other program

Code:
awk 'FNR==1{i++}{LC[i]=NR} 
{for(k=1; k<=NF; k++) A[i,FNR,k]=$k}                                 
END{for (i=1;i<=LC[1];i++)
{
for(j=1;j<=LC[2];j++)
if(A[2,j,8]=='$UID' && A[2,j,4]>='$MX'+A[1,i,3] && A[2,j,4]<='$MIN'+A[1,i,4] && \
A[2,j,4]>='$MN'+A[1,i,1] && A[2,j,5]<='$MX'+A[1,i,2])
print A[2,j,6],A[2,j,7]
}}' OFS="\t" STD_FIILE FILE2 | program(print) command -XA[2,j,5] -Y[2,j,5]   -------------> if statement is true

if if statement is awk program in false

then

Code:
OFS="\t" STD_FIILE FILE2 | program(mask) command -XA[2,j,5] -Y[2,j,5]   ------------->

please help me

if not possible please give me solution in bash
Hi Akshay,
I think we're unable to help you because we're unable to figure out what you're trying to do.

We don't know what is in your input files.
We don't know what the values of the shell variables MAX, MIN, MN, and UID are.
We can assume that LC[1] is the number of lines in the 1st input file, but why is LC[2] set to the number of lines in both input files instead of the number of lines in the 2nd input file?
How are:
Code:
program(print) command -XA[2,j,5] -Y[2,j,5]
     and
program(mask) command -XA[2,j,5] -Y[2,j,5]

supposed to be processed? (That isn't valid shell command syntax. Is the j in these commands supposed to be related to the j in the 2nd for loop in the END clause in your awk script? Are XA[2,j,5] and Y[2,j,5] supposed to be related to the awk script's array element A[2,j,5] )?
Are you trying to pipe the output of the print statement in your awk script to one command and have the same output piped to a different command if the if statement doesn't print anything? Is it possible that you want something like:
Code:
if(complex_condition)
        print A[2,j,6],A[2,j,7] | true_command
else
        print A[2,j,6],A[2,j,7] | false_command

as a replacement for the if statement in the END clause in your awk script?
This User Gave Thanks to Don Cragun 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

Tweak python program to give result in json

Hi , Below is the script which prints result in json but when i validate it has some tab or extra space issues. JSON result { "data": } This is the line I tweaked. Please advise. print "\t{", "\"{#NAME}\":\""+container+hn+"\"}" #!/usr/bin/env python # (2 Replies)
Discussion started by: ashokvpp
2 Replies

2. Shell Programming and Scripting

Piping through grep/awk prevents file write

So, this is weird... I'm running this command: iotop -o -P -k -bt -d 5 I'd like to save the output relelvant to rsyslogd to a file, so I do this: iotop -o -P -k -bt -d 5 | grep rsyslogd >> /var/log/rsyslogd Nothing is written to the file! I can write the full output to the file: ... (2 Replies)
Discussion started by: treesloth
2 Replies

3. UNIX for Dummies Questions & Answers

Weird: unexpected result after piping a sort

Hello, And when you think you know the basics of something, UNIX in this case, something like what I will describe below comes along.... On a Linux system, a "typical" directory with some files. Say 20. I do: > ls | sort > mylisting Now when I: > vi mylisting There is mylisting... (13 Replies)
Discussion started by: stavros
13 Replies

4. Shell Programming and Scripting

piping from grep to awk without intermediate files

I am trying to extract the file names alone, for example "TVLI_STATS_NRT_XLSTWS03_20120215_132629.csv", from below output which was given by the grep. sam:/data/log: grep "C10_Subscribe.000|subscribe|newfile|" PDEWG511_TVLI_JOB_STATS.ksh.201202* Output: ... (6 Replies)
Discussion started by: siteregsam
6 Replies

5. Shell Programming and Scripting

Executing the result of a program as a shell script

I have a program that returns a shell script and I want to execute the script. I'll use cat in my simple example, but wget is an example that is feasible. $ # First setup a script $ echo "ls > df" > simple $ # "cat simple" is now a program that returns a script $ cat simple ls df $ ... (3 Replies)
Discussion started by: kopite
3 Replies

6. Programming

Test program not giving expected result

I have five classes. 2 composition classes,1 aggregation class and 1 dependency class.I have coded all the classes but one of my test program is not giving me the expected result.I have the following classes: TimeStamp Interval (composition of 2 TimeStamps) TimeSheet ( aggregation of many... (3 Replies)
Discussion started by: moraks007
3 Replies

7. Shell Programming and Scripting

sort piping to awk array - help please

Hi I'm just learning programming and need some help. I've taken a data file which has a list of numbers eg: 3 5 32 533 13 2 And I've used sort -n and to sort and then piped it to awk to arrange into an array. #!/bin/sh sort -n data.txt | awk ' { array=$1 } (4 Replies)
Discussion started by: EL_Chemso
4 Replies

8. Shell Programming and Scripting

Way to save output result of a program into another new file...

Does anybody know any alternative way to save output result of a program into another new file? I got try the command below: program_used input_file > new_output_file program_used input_file >> new_output_file Unfortunately, both the ">" and ">>" is not work at this case to save the output... (6 Replies)
Discussion started by: patrick87
6 Replies

9. UNIX for Dummies Questions & Answers

Using awk to get a line number to delete, piping through sed

Alright, I'm sure there's a more efficient way to do this... I'm not an expert by any means. What I'm trying to do is search a file for lines that match the two input words (first name, last name) in order to remove that line. The removal part is what I'm struggling with. Here is my code: echo... (4 Replies)
Discussion started by: lazypeterson
4 Replies

10. Programming

Help with piping program

Hi, I am trying to write a program that will pipe any number of programs together like in the linux shell. As an example, the below code tries to execute "cat data | grep int | cut -b 1-10." The problem is that the programs never get executed for some reason. It seems like the first program... (3 Replies)
Discussion started by: PuppyHusher
3 Replies
Login or Register to Ask a Question