Tag Archives: output redirection

UNIX shell, from simple to complex

We used some very simple commands during our first lab. Let see a new command. This post shows how to use two handy features of the shell: output redirection and program piping.

grep¬†look for a patter into a line, and print it only if the pattern is present in the line. If we have a multifasta file, each header has a “>” sign. If we want to view all headers we can type:

grep ">" multifasta.fa

Output redirection

Most UNIX commands prints their output to screen. If we want to save that output we can use the “>” character:

ls -l > filelist.txt

we won’t see as usual the file listing with this command, because the “>” redirects ls’s output to the filelist.txt file. If we print the file:

cat filelist.txt

we will have a proof.

Program “pipes”

A very useful feature of the UNIX shell is the possibility to send the output of a program to another program. This is done with the pipe character: |.

ls -la | head -n 3

With this command we will see the first three lines of the ls output. Nice?

cat multifasta.fa | grep ">" | wc -l
  • can you guess what happens with this command???
  • can you write a command that prints only files created in march? (answer with comments)
Tagged , , , ,