Linux Tips
Awk quick tips
A few things learned while using awk.
- Massage files from a n-column format into an one-column format:
- awk '{ for(i=1;i<=NF;i++) print $i }'
- Inverse the z coordinates in a list of points:
- awk '{ printf " % 9.8F % 9.8F % 9.8F\n", $1, $2, -$3 }'
- Rescaling columns two and three of a data file by 1/2:
- awk '{ printf " % 8.7E % 8.7E % 8.7E\n", $1, $2/2, $3/2 }'
- Substracting columns two and three from different data files, skipping empty lines and comments (#):
- awk '{c2=$2; c3=$3; getline<f} NF>0 && $1!="#" {$2-=c2; $3-=c3} 1' f=file1 file2
Internal variables.
- NF : number of fields on the current line
- NR : line number (including all files processed thus far)
- FNR : line number (for the current file only)
Cluster management tips
Getting the list of installed packages.
- yum list installed > packages.lst
Reproducing the list of installed packages on the target machine (omitting i386 packages).
- yum install `grep -v i386 packages.lst | awk '{ print $1" " }' `
Make internal macros
For quick reference.
- $@ : the current target
- $^ : all dependencies
- $? : only those dependencies that are newer than the target
- $< : in a suffix rule, the dependency that triggered the rule
- $* : in a suffix rule, the filename part of the rule, without suffix
Advanced features.
- $$@ : the current target, used as a dependency
- $% : in a parenthesis rule, the parenthesized string
Changing root's password
Changing the password for root using GRUB bootloader.
- Restart, wait for GRUB boot loader to load
- Select Kernel, type, "e" for edit
- Select the kernel line, type "e" to edit
- Add "single" at end of line, type Enter
- Type "b" to boot
- After boot, enter "password root" at command prompt
- Enter new password for root
- Reboot (can type "shutdown -r now")