Search icon CANCEL
Subscription
0
Cart icon
Your Cart (0 item)
Close icon
You have no products in your basket yet
Arrow left icon
Explore Products
Best Sellers
New Releases
Books
Videos
Audiobooks
Learning Hub
Free Learning
Arrow right icon
Arrow up icon
GO TO TOP
Command Line Fundamentals

You're reading from   Command Line Fundamentals Learn to use the Unix command-line tools and Bash shell scripting

Arrow left icon
Product type Paperback
Published in Dec 2018
Publisher
ISBN-13 9781789807769
Length 314 pages
Edition 1st Edition
Languages
Tools
Arrow right icon
Author (1):
Arrow left icon
Vivek Nagarajan Vivek Nagarajan
Author Profile Icon Vivek Nagarajan
Vivek Nagarajan
Arrow right icon
View More author details
Toc

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...
lock icon The rest of the chapter is locked
Register for a free Packt account to unlock a world of extra content!
A free Packt account unlocks extra newsletters, articles, discounted offers, and much more. Start advancing your knowledge today.
Unlock this book and the full library FREE for 7 days
Get unlimited access to 7000+ expert-authored eBooks and videos courses covering every tech area you can think of
Renews at $19.99/month. Cancel anytime
Banner background image