Skip to Content
Linux Shell Scripting Cookbook - Third Edition
book

Linux Shell Scripting Cookbook - Third Edition

by Clif Flynt, Sarath Lakshman, Shantanu Tushar
May 2017
Beginner
552 pages
28h 47m
English
Packt Publishing
Content preview from Linux Shell Scripting Cookbook - Third Edition

How to do it...

A text file database can be built with common shell tools.

To create an address list, create a file with one line per address and fields separated by a known character. In this case, the character is a tilde (~):

    first last~Street~City, State~Country~Phone~

For instance:

    Joe User~123 Example Street~AnyTown, District~1-123-123-1234~

Then add a function to find lines that match a pattern and translate each line into a human-friendly format:

    function  addr {
        grep $1 $HOME/etc/addr.txt | sed 's/~/\n/g'
    }

When in use, this would resemble the following:

    $ addr Joe
    Joe User
    123 Example Street  
    AnyTown District
    1-123-123-1234
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Start your free trial

You might also like

Mastering Linux Shell Scripting - Second Edition

Mastering Linux Shell Scripting - Second Edition

Mokhtar Ebrahim, Andrew Mallett

Publisher Resources

ISBN: 9781785881985