awk (continued) - General form of awk statements pattern {action} - if the pattern is matched action is taken - default pattern matches every line - default action is print $0 - two special paterns are BEGIN and END - Other examples - print out first field of all the lines which have null string as the second field awk -F: '$2==""{print $1}' /etc/passwd - print out first field of all the lines which have tcsh in the last field awk -F: '$NF~"tcsh"{print $1}' /etc/passwd - awk uses all the C operators plus more == comparison != not equal <,>,<=,>= ~ comparing regular expressions (not from C) !~ is opposite of ~ && means and || means or ! means not - sort command sort a file awk -F: '{print $1,$(NF -2)}' /etc/passwd | sort +2 - We are sorting the output from awk based on the third field - +2 specifies the offeset which will be the third field - -n ro sort numerically instead of alphabetically - -r for reverse - -t for field separator, -i for case insensitive sort - the command tr is used for translation - the following command translates uppercase to lowercase tr A-Z a-z < /etc/passwd Backups - Note all of these commands are executed on machine called satara - mount allows you to mount a file system - mount -F nfs wascana:/ /wascana - The above command mounts root partition from wascana at mount point /wascana - tar cvf /wascana/extra/satara.tar . - The above command tars everything from . down into a file /wascana/extra/satara.tar - option c is for creating or rewinding the device - option v for verbose - f specifies the device by default the device is /dev/rmt/0 - tar tf /wascana/extra/satara.tar - above command gives us the table of contents for the tar file - tar xvf /wascana/extra/satara.tar ./.cshrc - above command extracts ./.cshrc from the tar file - if you did not specify the filename, every file is extracted. - tar backs up everything from the specified directory down, irrespective of the file system. - ufsdump command only backs up a file system - dump2 is similar to ufsdump - An example of ufsdump command: ufsdump 0uf /dev/rmt/0hn /dev/dsk/c0t3d0s0 - 0 stands for complete backups - you can also specify 1,2,3...7 levels instead of 0 - level 1 backsup everything modified from last level 0 backup - f specifies the device, default is /dev/rmt/0 - n in 0hn stands for not rewind after backing up the current file system - the last argument is the file system - ufsrestore is used for extracting files. It may be better to do it through the sysadm.