Pages

Tutorial for a Unix Join

The Unix join command takes two text files as input and joins lines that start with a common text field together, dropping other lines in the text files where they don't share the text field at the beginning of the line in common. For example, if you have two files, one with "abc 123" and "abc 456," and perform a join on them, the command prints "abc 123 456" into the standard terminal output. However, if you have two files, one with "123 abc" and "456 abc," the join command prints nothing, since neither line starts with the same text. You can configure join to match other text fields with command line switches.

Instructions

  1. Open a terminal by clicking "Applications," "Accessories" and "Terminal."
  2. Use the "cd" command to enter the directory containing the text files you want to run the join command on. For example, type "cd Documents" into the terminal and press "Enter" to enter the Documents directory.
  3. Type "join file1 file2," replacing "file1" and "file2" with the names of the files, into the terminal and press "Enter." The join command combines each line that begins with the same text and prints the combined line in the terminal.

0 comments:

Post a Comment