• Skip to primary navigation
  • Skip to main content
  • Skip to primary sidebar

The Urban Penguin

The Urban Penguin - Linux Training

  • Home
  • About
  • Programming
    • Master Editing Text Files Using VIM
    • Learn Shell Scripting with BASH
    • PERL Scripting in Linux
    • Ruby Scripting in Linux
    • Scripting with PowerShell
    • Learn C Programming using Linux and the Raspberry Pi
    • General Java Tutorials
    • Java 7 OCA Exam 1ZO-803
  • OS Tutorials
    • Red Hat and CentOS Training
      • Red Hat Enterprise Linux System Administration 1 – RH124
      • RHCSA – System Admin 2 – RH134
      • RHCE – EX294 – Automation With Ansible
    • Learning Ubuntu
    • LPI Training
      • LPI Linux Essentials
      • LPIC-1 Linux Administrator
      • LPIC-2 Certified Linux Engineer
      • LPIC-3 Senior Level Certification
        • LPIC-3 Exam 300 : Mixed Environments
        • LPIC-3 Exam 303 : Security
        • LPIC-3 Exam 304 : Virtualization and High Availability
    • Linux Technologies
      • Apache HTTPD Server
      • Learning PHP
      • Learning PUPPET
      • Learning SAMBA
      • Linux File-Systems
      • Monitoring with Nagios Core
      • MYSQL
      • openLDAP Directories on Linux
You are here: Home / Linux / LPIC-1 Exam 101 / 103.2 Process text streams using filters Part 3

103.2 Process text streams using filters Part 3

February 4, 2014 by The Urban Penguin

Key Knowledge Areas

  • Send text files and output streams through text utility filters to modify the output using standard UNIX commands found in the GNU textutils package.

Terms and Utilities

  • cat
  • cut
  • expand
  • fmt
  • head
  • od
  • join
  • nl
  • paste
  • pr
  • sed
  • sort
  • split
  • tail
  • tr
  • unexpand
  • uniq
  • wc

Join


The GNU join (/usr/bin/join) command is a little like a database join but with text files rather than databases. For a simple join we can use join file1 file2, but for more complex joins we specify the fields to join with join -1 3 -2 1 file1 file. It does seem a little of a mess but it does make sense when we get into it. Where possible though the data would best exist within databases.

Starting with a simple join would seem like the best idea. We have two text files: city and country:

1 London
2 Cardiff
3 Edinburgh
4 Belfast

1 England
2 Wales
3 Scotland
4 NI

The two files have matching first columns and they are in sort order, either numerical or alphabetical will suffice. If no additional options are provided to join statement then it will join the two files on column 1.

join city country

The output then show the city joined with the country, the column that is joined on shows just once.

In a more complex example we may want to join the employees and managers file:

 1 fred
 2 bill 1
 3 sally 1
 4 jim 2
 5 jane 2
 6 sue 3
 7 meg 3



The first column shows the employee ID, then the name and then the manager ID. The manager ID maps to an employees ID, as of course, the manager is also an employee.

A list of managers show in the managers file:

 1 fred
 2 bill
 3 sally

So now we must join column 3 from the employees table to column 1 in the managers table. This is specified in the join command as:

join -1 3 -2 1 employees managers

Fred does not show as he is not managed, if we want to show non-matching rows we can use the -v1 option with the join command to list non matches from file 1:

join -v1 -1 3 -2 1 employees managers

This will just list Fred:



Share this:

  • Click to share on Twitter (Opens in new window)
  • Click to share on Facebook (Opens in new window)
  • Click to share on LinkedIn (Opens in new window)
  • Click to share on Reddit (Opens in new window)
  • Click to share on Pinterest (Opens in new window)
  • Click to share on Tumblr (Opens in new window)
  • Click to print (Opens in new window)

Filed Under: LPIC-1 Exam 101

Primary Sidebar

Newest Video

The Urban Penguin On Youtube

Categories

Pages

  • About The Urban Penguin
  • Contact Us
  • Linux Technologies
    • Apache HTTPD Server
    • Learning PHP
    • Learning PUPPET
    • Learning SAMBA
    • Linux File-Systems
    • Monitoring with Nagios Core
    • MYSQL
    • openLDAP Directories on Linux
  • LPI Training from The Urban Penguin
    • Complete Linux Essentials
    • Live and Pluralsight hosted courses
    • LPI Linux Essentials
    • LPI Linux Essentials for Raspberry Pi
    • LPIC-1 Linux Administrator
    • LPIC-2 Certified Linux Engineer
    • LPIC-3 Senior Level Certification
      • LPIC-3 Exam 300 : Mixed Environments
      • LPIC-3 Exam 303 : Security
      • LPIC-3 Exam 304 : Virtualization and High Availability
  • Online Instructor-led Courses
    • Bash Scripting Masterclass
    • Nftables Masterclass
    • Red Hat Enterprise Linux System Administration 1 – RH124
    • SELinux Masterclass
  • OpenStack
    • Citrix Videos
    • Pluralsight
    • Raspberry Pi Tutorials
    • Udemy
  • Operating System Tutorials
    • Learning SUSE
    • Learning Ubuntu
    • Linux Foundation Training
    • Red Hat and CentOS Training
      • RHCE – EX294 – Automation With Ansible
      • RHCSA – System Admin 1 – RH124
      • RHCSA – System Admin 2 – RH134
    • Solaris 11 OCA 1ZO-821
  • Scripting – the power of repetition!
    • General Java Tutorials
    • Java 7 OCA Exam 1ZO-803
    • Learn C Programming using Linux and the Raspberry Pi
    • Learn Shell Scripting with BASH
    • Master Editing Text Files Using VIM
    • PERL Scripting in Linux
    • Ruby Scripting in Linux
    • Scripting with PowerShell

© 2022 The Urban Penguin · All Rights Reserved