[go: up one dir, main page]

0% found this document useful (0 votes)
42 views2 pages

Bash Course - Tutorial 2: File Renamer

This document provides instructions for writing a Bash script to manage personal contact information. The script should allow users to add, delete, find, and list contacts by first name, last name, email, and phone number. Regular expressions and Bash tools like cat, cut, sed, awk, grep, and sort should be used to validate input and process the contacts database. The script accepts command line parameters to specify the desired action and filters. Functions are defined to implement each action.

Uploaded by

anidcohen9058
Copyright
© Attribution Non-Commercial (BY-NC)
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
42 views2 pages

Bash Course - Tutorial 2: File Renamer

This document provides instructions for writing a Bash script to manage personal contact information. The script should allow users to add, delete, find, and list contacts by first name, last name, email, and phone number. Regular expressions and Bash tools like cat, cut, sed, awk, grep, and sort should be used to validate input and process the contacts database. The script accepts command line parameters to specify the desired action and filters. Functions are defined to implement each action.

Uploaded by

anidcohen9058
Copyright
© Attribution Non-Commercial (BY-NC)
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 2

Tobias Neckel

Max-Planck, October 2013

Bash course - Tutorial 2


File renamer
Sometimes, large numbers of les have to be renamed, e.g. by adding a prex, appending a sux or replacing a certain pattern. In this task, you should write a program doing that automatically. The program should have three dierent modes: ./file renamer prefix <prefix> <file>+ ./file renamer suffix <prefix> <file>+ ./file renamer replace <pattern> <replacement> <file>+ a) If the prex mode is executed, the given prex should be added to all lenames b) If a le has no ., the sux should just be appended to the lename. But if there is a . in the lename, the sux should be appended before the dot. So name.txt should become namesux.txt and name should become namesux c) The replace-mode just applies the given pattern

Personal Address Manager


In this task, you have to implement a basic address manager, which you can use to add contact information (rst name, last name, email and phone number) to a local database, search for entries, delete entries, ... There are many ways to solve the task, even avoiding all bash tools and implementing everything yourself using basic control structures. But the purpose of this task is to practise the use of regular expressions and several of todays bash tools, e.g. cat, cut, sed, awk, grep, sort, ..., so really try to make use of these tools. a) As a start, let your program accept the following parameters: -a add a new entry -d <field>=<value> [<field>=<value>...] delete all entries which satisfy all conditions -f <field>=<value> [<field>=<value>...] nd all entries which satisfy all conditions

2 -l <sortcolumn> where <sortcolumn> is one of {firstname, lastname, email, phone}. Lists all entries sorted by the given column. You can use the following code-block to process the parameters: case $1 "-a" "-d" "-f" "-l" esac in ) add;; ) shift; delete $*;; ) shift; find $*;; ) shift; list $*;;

add, delete, nd and list are four functions which you will have to implement. b) Implement the add function. It should query the user for rst name, last name, email and phone number. For the email, it should be checked whether the entered string is a valid email address. If not, the user should be asked again. Accepted telephone numbers should consist of numbers and whitespaces, one - or / is allowed as separator, e.g.: 089 289 18 636 089 / 289 18636 089-28918636 Use regular expressions to ensure that all such phone numbers are accepted. Before storing them, you should transform them such that they match the pattern [[:digit:]]\+/\?[[:digit:]]\+, which means that all whitespaces should be removed and only / should be used as a separator (or no separator at all). c) Implement all other functions (delete, nd, list)

You might also like