Shell One Liners

May 21, 2010 mohancheema 0

Renaming file name.old to name.new – To test things first, insert ‘echo’ between ‘do mv’ (below).

$ for i in *.input; do mv $i ${i/name.old/name.new}; done

Running application in loops on many input files

$ for i in *.input; do ./application $i; done

AWK One Liners

May 21, 2010 mohancheema 0

Simple AWK programs enclosed in single quotes can be typed and executed right at the Unix prompt. For example, the program

awk ‘BEGIN { FS = “:” } { print $1 | “sort” }’ /etc/passwd

This program prints a sorted list of the login names of all users.

No Picture

SED One Liners

April 28, 2010 mohancheema 0

FILE SPACING

  • double space a file
sed G
  • double space a file which already has blank lines in it. Output file should contain no more than one blank line between lines of text.
sed '/^$/d;G'
  • triple space a file
sed 'G;G'
  • undo double-spacing (assumes even-numbered lines are always blank)
sed 'n;d'
  • insert a blank line above every line which matches “regex”
sed '/regex/{x;p;x;}'
  • insert a blank line below every line which matches “regex”
sed '/regex/G'
  • insert a blank line above and below every line which matches “regex”
sed '/regex/{x;p;x;G;}'

No Picture

Perl One Liner

April 28, 2010 mohancheema 0

List of one line perl programs to do many common command-line tasks.

  • run contents of “my_file” as a program
perl my_file
  • run debugger “stand-alone”
perl -d -e 42
  • run program, but with warnings
perl -w my_file
  • run program under debugger
perl -d my_file