How to alias an awk command with single and double quotes?

Hi,

I am trying to write the following command as an alias in my .bashrc file.

bjobs -u all | awk '{if (NR > 1) {username[$2]++;}}END{{print"\nJOBS BY USER:\n"} for (i in username) {print username,i;}{print"\n Total Jobs=",NR-1,"\n" }}'

The command simply puts how many jobs each user is running and works correctly from the command line.

How do I write it in my .bashrc file, given that the format of the alias command is:

alias [i]aliasname='command';

Obviously the following does not work since two instances of single quotes get confused:

alias bju='bjobs -u all | awk '{if (NR > 1) {username[$2]++;}}END{{print"\nJOBS BY USER:\n"} for (i in username) {print username[i],i;}{print"\n Total Jobs=",NR-1,"\n" }}' ';

I tried using double quotes around awk and escaping the double quotes inside the command but that has not worked.

Please help if you can.

Create a shell function instead call it bju()

Thanks a lot Jim!

I have no experience in unix so you helped a lot.

This worked great:

bju () { bjobs -u all | awk '{if (NR > 1) {username[$2]++;}}END{{print"\nJOBS BY USER:\n"} for (i in username) {print username[i],i;}{print"\n Total Jobs=",NR-1,"\n" }}'; }