I want to print different lines to different output files using awk, depending on different conditions, like
awk '{if($2>10) print > outfile1; else print > outfile2}' infile
but this script doesn't work how to modify it? thanks!>
To print a blank line, use print "" , where "" is the empty string. To print a fixed piece of text, use a string constant, such as "Don't Panic" , as one item. If you forget to use the double-quote characters, your text is taken as an awk expression, and you will probably get an error.
Yes, you can read from multiple files at the same time using awk. In order to do that, you should use the getline command to explicitly control input. In particular, you want to use getline with a file so that you're not reading from the file(s) passed in as main arguments to awk.
awk '{ print $2; }' prints the second field of each line. This field happens to be the process ID from the ps aux output. xargs kill -${2:-'TERM'} takes the process IDs from the selected sidekiq processes and feeds them as arguments to a kill command.
# Tell awk to print the third input record of the current file. awk 'FNR==3 {print}' my. txt.
You need to close the file names in double quotes:
awk '{if($2>10) {print > "outfile1"} else {print > "outfile2"}}' infile
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With