Wednesday, 29 August 2012

Text tools in Linux

Here is the list of essential Linux text tools with short description of their functions

  • cat - shows file in standard output
  • tac - shows file in standard output in reverse order
  • join - combines files by field
  • paste - merges files line by line
  • expand - converts tabs to spaces
  • od - dump files in octal and other formats
  • sort - sort text files, sing fields(symbolic or numerical)
  • split - splits files to pieces by bytes or by number of lines.
  • tr - translate or delete characters
  • unexpend - convert spaces to tabs
  • uniq - delete duplicate lines
  • fmt - simple text formatter, for example it splits long lines.
  • nl - number lines in a file
  • pr - convert text files for printing.
  • head - shows the beginning of the file.
  • tail - shows some from the end of the file.
  • less - text file reader.
  • cut - remove sections from each line of files
  • wc - counts lines, bytes and words
  • sed - stream editor
  • grep - print lines matching a pattern
  • egrep - grep with activated(-E option) extended regular expressions
  • fgrep - fixed-string grep

And here are the main Vi commands

Command mode:

  • p - paste text
  • 3yy - copy 3 lines
  • 3dd - delete 3 lines
  • u - undo
  • h,j,k,l - move cursor
  • o - insert new line and enter insert mode
  • i - enter insert mode before cursor
  • R - enter insert mode for text replacement
  • a - append text after cursor
  • / - search forward
  • ? - search backward
  • c - change text
  • G - goes to specified line
  • :%s/original/replacement - replace globally
  • Ctrl+F - move one screen ahead
  • Ctrl+B - move one screen back
  • Ctrl+D - go down half screen
  • Ctrl+U - go up half screenExec mode:
  • e or e! - edit another file
  • r - include file
  • ! - execute external command
  • q - quit
  • w - save
  • ZZ - save and exit
Tips
To translate Windows/Dos text file, where CR+LF are the end of the line, to Linux text file, where LF is the end of a line, tr program can be used:

tr -d '\r' < input_file > output_file



Ping does not work

Today I would like to discuss a banal situation: host A is directly connected to host B, ping from host A to host B does not work. What are...