zcf1025@dpscg1.UUCP (Regina Dawley) (09/27/89)
Hello World, As a novice to the Awk programming language, i'm having a problem with my script. First, i'm reading a data file using the getline function; Secondly, i'm assigning the data line to $0; Next, i'm selecting the first 5 lines from another data file using the head command and redirecting the output to a file. Next, i want to print $0 and append it to the file containing the 5 lines. This statement does not execute. Does anyone have an answer? The script follows. Thanks Regina Dawley autovon 8-444-7508 215-952-7508
zcf1025@dpscg1.UUCP (Regina Dawley) (09/27/89)
matchlines = 0
while ( getline < "temp.data" > 0) {
input[matchlines] = $0
system("head -5 < tale.data > tale.hdr")
print $0 >> tale.hdr
system("tail -29 < tale.data >> tale.hdr")
system("sprint tale.hdr")
matchlines++
}
hal@junkyard.UUCP (Hal Moroff) (04/09/91)
I'm trying to use awk to read an ascii file, and translate only
certain fields. I have my own special filter that will be used for the
translation.
I can get awk to read my input file and extract the desired fields.
I can also get it to invoke my filter passing those fields, however I cannot
get the filter return value assigned to a variable in my awk program.
My hands are slightly tied in that I cannot modify the way the
filter works.
An awk code fragment follows:
-------------------------------------------------------------------------------
#
# awk script to filter selected fields
#
#
BEGIN { }
/.*/ {
# the following statement works whether I use 'cat' or my own filter
print ">> " $1 | "cat"
# however I wish to retrieve the string output by my filter into
# a variable for further processing by 'awk'. I've tried:
# print ">> " $1 | "cat" | getline
# and also:
# print ">> " $1 | "cat" | getline str
# and both return the same error:
#awk: syntax error near line 14
#awk: illegal statement near line 14
}
END { }
-------------------------------------------------------------------------------
Sorry if this distribution is too wide/narrow. I've read notes
a long time, and posted rarely.
Reply by email here or to cognex!hal@ai.mit.edu
Thanx.
- hal