madasafish
Technical User
I want tbe able to call a nawk function that will print out a set of lines. The first time the function
is called it will print to the screen. The second time it is called I will call the funtion with a ">" at the end
to re-direct output to a file. I appreciate I could repeat all the lines with the ">" but cant help thinking
there must be a better way of doing this in Awk/Nawk
I have no problem dong this in "ksh" but am finding it very difficult to do with awk and nawk.
Is there an Awk/Nawk easy way do this?
#Example ksh program
function printsection
{
echo "This is line 1"
echo "This is line 2"
echo "This is line ...."
}
printsection
more code in here....
.......
.......
printsection > myfile
exit 0
#Awk/Nawk Program
nawk '{
function printawksection(){
printf "\n" "This is line 1"
printf "\n" "This is line 2"
printf "\n" "This is line ...."
}
} END {
printawksection
more code in here....
.......
.......
printawksection > myfile
}'
exit 0
is called it will print to the screen. The second time it is called I will call the funtion with a ">" at the end
to re-direct output to a file. I appreciate I could repeat all the lines with the ">" but cant help thinking
there must be a better way of doing this in Awk/Nawk
I have no problem dong this in "ksh" but am finding it very difficult to do with awk and nawk.
Is there an Awk/Nawk easy way do this?
#Example ksh program
function printsection
{
echo "This is line 1"
echo "This is line 2"
echo "This is line ...."
}
printsection
more code in here....
.......
.......
printsection > myfile
exit 0
#Awk/Nawk Program
nawk '{
function printawksection(){
printf "\n" "This is line 1"
printf "\n" "This is line 2"
printf "\n" "This is line ...."
}
} END {
printawksection
more code in here....
.......
.......
printawksection > myfile
}'
exit 0