Friday, September 14, 2012

Linux/Unix commands and utils


I will be putting all the simple unix helpful commands and utils over here. Starting with only couple of commands. Will be updating this on regular basis.
  • Calculating frequency of data in UNIX
    • Calculating frequency of some data in a plain text file. For example if the file has data in each line like as in this file. Then program should print frequency of numbers as output as given in this file.
    • awk '{x[$1] += 1}END{ for (entry in x) {print entry "-" x[entry]} }' 1.txt
    • Note that this can be applied to applied to any arbitrary pipe output also by appropriately select the data column number ($1 or $2 etc.)
  • Get range of lines from a file or output
    • The below command prints 2nd to 5th line of 1.txt file
      • awk 'NR>=2 && NR<=5 {print $1}' 1.txt
  • To know your IP from unix command line
    •  wget -qO- icanhazip.com

No comments:

Post a Comment

Post a Comment