NovaDenizen,
I got this when I ran the code and passed 3 variables to the script: $1, $2, $3, which are, respectively, logfile name, directory name (inthenews), name of results file :
**************************
awk: syntax error at source line 1
context is
>>> \ <<< inthenews\~/\/\//
awk: bailing out at source line 1
**************************
Looks like it thinks the $2 in "awk ' $2 ~..." should be the passed $2 variable and not the second field. It should be "awking" the second field ($2) for the $2 variable.
Yes? Clear as mud?
Thanks so much!
[Aside - Perl seems so dense compared to these little UNIX machines!]
Main Topics
Browse All Topics





by: NovaDenizenPosted on 2004-04-23 at 12:15:14ID: 10902942
I recommend that you switch over to perl. awk and sed are good for simple tasks, but perl has the power to do this in about a ten line script, and it would be easy to parameterize that.
Sermon over. The difficulty with parameterizing the variable in the awk statement is that the argument to awk is in single quotes, which do not permit expansion of variable names. The question is, can we rewrite this argument without using single quotes? The answer is yes, and we can do it by escaping individual characters.
Assuming $dir contains the directory,
awk \ \$2\ \~\ /\\/$dir\\//
should do the trick. Note that all spaces, the '$' in $2, the ~, and the backslashes are all individually escaped because we want awk to see them, and the $ in $dir is not escaped because we want ksh to expand the $dir variable. This way, ksh passes ' $2 ~ /\/dirname\//' as its sole argument.
It may also be possible to do it using double quotes, but I don't know the precise details off the top of my head.