Philip Morris
Philip Morris

Reputation: 469

How to print in a file using awk command inside a ksh file

How do I print in a .log file using awk command inside a ksh file? The script goes this way:

##create file here
## Start  process 
awk 'BEGIN {
        some code here
    }
    {

##Logic here
##Print to file 

    }
    END {}
' $OUTPUTNEEDEDTOBEPRINTED

Upvotes: 0

Views: 245

Answers (1)

Jotne
Jotne

Reputation: 41460

You can redirect within the awk code:

##create file here
## Start  process 
awk 'BEGIN {
        some code here
    }
    {
    print > "myfile"


    }
    END {}
' "$OUTPUTNEEDEDTOBEPRINTED"

Or just redirect the output of you awk

##create file here
## Start  process 
awk 'BEGIN {
        some code here
    }
    {

##Logic here
##Print to file 

    }
    END {}
' "$OUTPUTNEEDEDTOBEPRINTED" > "myfile"

Upvotes: 2

Related Questions