AWK/ksh interaction question
lwv27 at CAS.BITNET
lwv27 at CAS.BITNET
Sat Aug 4 05:46:00 AEST 1990
I am trying to parse a shell argument and pass the results down to an inline
awk script. A sample of the code that I am trying to use is:
--- Cut Here ---
#! /bin/ksh
# Assume 1 has -dx where x is a delimiter
# and 2 as the file name to read
delim=$(echo FS=\"$(substr "$1" 2 1)\")
file="$2"
awk '
BEGIN {
'$delim'
OFS=FS
}
{
printf ("NR=%d; NF=%d; FS=.%s.; OFS=.%s.\n", NR, NF, FS, OFS)
printf ("%s%s%s", $5, OFS, ORS)
}
' $file
--- Cut Here ---
If I invoke this as:
tst1 -d: /etc/passwd
I get what I expect. But, if I invoke this as:
ksh -x tst1 '-d ' /etc/passwd
awk claims that there is a syntax error. What is strange is that if I
type in an awk script of:
--- Cut Here ---
awk '
BEGIN {
FS=" "
OFS=FS
}
{
printf ("NR=%d; NF=%d; FS=.%s.; OFS=.%s.\n", NR, NF, FS, OFS)
printf ("%s%s%s", $5, OFS, ORS)
}
' $file
--- Cut Here ---
then it seems to work just fine. Same expansion. Can anyone give me
a suggestion around this problem?
Thanks!
--
Larry W. Virden
Business: UUCP: osu-cis!chemabs!lwv27 INET: lwv27%cas.BITNET at CUNYVM.CUNY.Edu
Personal: 674 Falls Place, Reynoldsburg,OH 43068-1614
Proline: lvirden at pro-tcc.cts.com America Online: lvirden CIS: [75046,606]
More information about the Comp.unix.questions
mailing list