Book Image

Command Line Fundamentals

By : Vivek Nagarajan
Book Image

Command Line Fundamentals

By: Vivek Nagarajan

Overview of this book

The most basic interface to a computer—the command line—remains the most flexible and powerful way of processing data and performing and automating various day-to-day tasks. Command Line Fundamentals begins by exploring the basics, and then focuses on the most common tool, the Bash shell (which is standard on all Linux and iOS systems). As you make your way through the book, you'll explore the traditional Unix command-line programs as implemented by the GNU project. You'll also learn to use redirection and pipelines to assemble these programs to solve complex problems. By the end of this book, you'll have explored the basics of shell scripting, allowing you to easily and quickly automate tasks.
Table of Contents (6 chapters)

Chapter 2: Command-Line Building Blocks

Activity 6: Processing Tabular Data – Reordering Columns

  1. The following commands are to be used in the given order:
    robin ~/Lesson2 $ tail -n+2 land.csv | sort >sorted.txt
    robin ~/Lesson2 $ cat -n sorted.txt >numbered.txt
    robin ~/Lesson2 $ cat -T numbered.txt | head -n3
      1^IAfghanistan,AFG,1961,57.7459179609717
      2^IAfghanistan,AFG,1962,57.8378212786815
      3^IAfghanistan,AFG,1963,57.914407376773
    robin ~/Lesson2 $ tr ',' '\t' <numbered.txt >tabbed.txt
    robin ~/Lesson2 $ cat -T tabbed.txt | head -n3
      1^IAfghanistan^IAFG^I1961^I57.7459179609717
      2^IAfghanistan^IAFG^I1962^I57.8378212786815
      3^IAfghanistan^IAFG^I1963^I57.914407376773
    robin ~/Lesson2 $ join -o1.4,1.5,1.3 tabbed.txt tabbed.txt >342.txt
    robin ~/Lesson2 $ join -o1.5,1.4,1.2 tabbed.txt tabbed.txt >431.txt
  2. To view the expected content in the two output files, use the following...