Print Particular Lines of a File Using SED

Say you want to print the lines 3 and 7, and all lines from 11 to 15 of a text-file. The following SED one-liner will do for you
sed -n -e ‘3p’ -e ‘7p’ -e ‘11,15p’ textfile.txt

Working with a List of Tuples in Shell Scripting

Several people have recently asked me whether or not it is possible to use tuples in their shell script. One example is running a program with a varying set of parameters. Since they often did not find a good solution, they began to formulate their problem in a higher-level scripting language like Ruby. Surprisingly, you [...]

List Only Subdirectories for Shell Scripting

I like to have the following snippet in my .zshrc (or .bashrc) for convenience
alias lsd=”ls -l|awk ‘/^d/ {print \$9}’”
It displays all subdirectories underneath the current directory. The goodness in this variant is that it gives you the pure names and that you can use it in loops without hassle :
for d in `lsd`; do
mv $d/resultfile.dat [...]

Activate extended globbing!

This one is for zsh users. As you read this, open your editor at once an add the following line to your .zshrc
setopt extendedglob
This will activate extended globbing and allow you to do even more zsh commandline candy. Here some examples
rm ^important.txt # remove all files in the current dir but important.txt
rm *.log~apache.log # [...]

Moving or Renaming Multiple Files – The Easy (zsh) Way

Linux workers like you and me often need to move a bunch of files. For example, you want to rename all *.dat files into *.dat_save, or you want to rename all files foo.* into something like bar.*. This, however, is not easy to do using the move command as 1) “mv” only supports a single [...]

How to get an entry out of a tab delimited file

Insert the following function into your .bashrc:
# Function that gets a column and row from a tab separated file
tableEntry()
{
sed -n “$1p” $3 | awk ‘{print $’$2′}’
}
You are then able to write
tableEntry 2 5 file.txt
to get the 2nd row and 5th column from any file.