Quoting quotes in awk

mo at wgivax.UUCP mo at wgivax.UUCP
Wed Mar 5 23:28:26 AEST 1986


>From ken at turtlevax.UUCP (Ken Turkowski) Sun Feb  6 01:28:16 206

>How does one quote quotes in awk?  I'd like to do something like the following:

>	print doit "\"" last0 "\"", "\"" $0 "\"" | "sh"

>Alternatively, I'd like to execute the program "doit" with arguments
>determined from the awk program:

>	print "" | doit "\"" last0 "\"", "\"" $0 "\""

execute 'awk -f <filename>' where file <filename> has following awk commands:

BEGIN {Q = "\""}
NR > 1 {printf("doit %s %s %s %s %s %s | sh\n",Q,last,Q,Q,$0,Q)}
NR > 1 {printf("%s%s | doit %s %s %s %s %s %s\n",Q,Q,Q,last,Q,Q,$0,Q)}
{last = $0}

note that this could also be done directly in sh, and, depending on exactly
what you are trying to do, you might be able to save some steps in getting
the command generated by "doit" to execute.  following is an example of
how to do it in sh:

lastline=""
read line
while (test $line)
do
	if(test $lastline)
	then
		echo 'doit " '$lastline' " " '$line' " | sh'
	fi
	lastline=$line
	read line
done

note that this script expects input to be given to it



More information about the Comp.unix mailing list