0

can some one please explain to me how to do multiple if statements and nested if statements in an awk line? I am using the awk command in a CShell program.

My code:

awk '{split ($2,b,""); if (b[1-] == 1) {printf("%s%s%s\n","'$letter'","'$year2'")}}' fileRead >> $year$cmonth           

My goal is to make this command have the if statement above with two more if statements nestled in it. Cmonth is just a counter of months from 1-12. Year2 is just a year. I can show an example of what I want in java because I know how to do it in java.

Java Code of what I desire:

if (b(some counter) == 1)
{
    if (some counter < cmonth)
        use year2
    else if (some counter > cmonth) 
        use year3
    else
        fail
}
else
    fail

Just have not been able to find the answer on the internet. Thanks for any help.

Danny
  • 117
  • 1
  • 7
  • 1
    Just to ask: do you know you can use an external source file with awk using the "awk -f " syntax? Why do you want to do it on a single line? (not that it couldn't be done in a line, probably it's possible to do that also) – friol Jul 09 '13 at 19:48
  • This is my first week of using awk, so I am very limited in my knowledge of how to use it. I was thinking that it would be much easier if awk did not have to be one line. I did not know you can call a file. Unfortunately, I still do not know how to create an awk file with multiple lines or call a file like you suggested. – Danny Jul 09 '13 at 19:52
  • please work your way thru an awk tutorial, you'll save yourself a lot of pain. Maybe http://www.grymoire.com/Unix/Awk.html ? Good luck. – shellter Jul 09 '13 at 21:41
  • do you still need help with this? Good luck to all. – shellter Jul 10 '13 at 17:04
  • Might I recommend you change the title to "Using if statements in awk" or something like that? The title makes one thing this is a csh question, when really it's an awk question. You might also want to add an awk tag. You will probably get a response from someone who knows awk when you do that. – SethMMorton Jul 11 '13 at 03:53

0 Answers0