Hi,
I wrote an awk script to analyse file A.
I call the script with files A and B. File A has lines like:
000000033100001
000000036100001
000000039100001
The first 9 characters are interpreted as a line number;
for each line number found I want to output this line number of file B.
searching around my idea was to use sed to output the line number, and system call sed inside awk...but the script below does not work, the call to sed fails. maybe just because the line_nr variable isnt correctley passed.
Can someone help me how to correctely write the call to sed or solve the problem inside awk?
regards
kp
awk 'BEGIN {
printf("line %5s result code %12s record_id\n","","")}
{
line_nr=substr($1,0,9);
res_code=substr($1,10,3);
rec_id=substr($1,13,3);
printf("%09i ", line_nr);
printf("%03i %-20s ", res_code, rescode[res_code+0]);
printf("%03i %-40s\n", rec_id, recid[rec_id+0]); # +0 needed to convert string rec_id to number
system("sed -n \"line_nr p\" $2");
}' $1
---------- Post updated at 10:26 AM ---------- Previous update was at 10:15 AM ----------
[/COLOR]ok, shame on me for finding this too late. the passing of variables to the system call is done via sysstring; the second file i passed via "-v sourcefile=$2" to awk:
sysstring=sprintf("sed -n \"%i p\" %s", line_nr, sourcefile);
system(sysstring);
so, the modified awk script works. the question remains: possible without system call?