How can I pass arguments to system command in a awk script?

Hi

I need your help, please

How can I pass arguments to system command in a awk script?... for example:

byte=substr(cadena,pos,2);
system("grep -n byte  mapeo.txt");

Does it exist a way?

Thanks for advance.

byte=substr(cadena,pos,2);
cmd = "grep -n  "byte"  mapeo.txt"
system(cmd);

Hi

I apreciate your helping, I only want to ask another question, please

byte=substr(cadena,pos,2);
cmd = "grep -n  "byte"  mapeo.txt"
system(cmd);

if I want to take the output of command system on a variable; Is it that possible? ...I try using

cmd = "grep "byte"  mapeo.txt | awk '{"ascii_dec"=$2}'"

however I had that:

awk: l�nea ord.:1: {=$2}
awk: l�nea ord.:1:  ^ syntax error

Thank you :slight_smile:

in following thread there is one function named Cmd copy and paste in your program and then execute your system commands

Help me in the Execution of Date comparsion by Akshay Hegde - UNIX for Dummies Questions & Answers - Unix Linux Forums

Cheers..

thanks for your help Akshay Hegde :b:

function Cmd(cmde,result){
                              while ((cmde | getline line) > 0)
                                  {
                                      result = result (result=="" ? "" : "\n")line
                                  }
                              close(cmde)
                              return result
                         }

function convierte()
{
 cadena=$0;
 longitud=length(cadena);
 pos=1;
 byte=substr(cadena,pos,2);
 resul=Cmd("grep "byte"  mapeo.txt|awk '{print $2}'");
 print resul;
}