Purchase Solution

Shell scripting: concatenate the argument lists

Not what you're looking for?

Ask Custom Question

Write a Bash script to concatenate the argument lists and output the resulting list. Final list should not include any argument that is a sub-list of the entire list. The script should not leave any redundant elements in the concatenated list, and it should maintain the order of the elements in the input. Examples below give a better idea about expected script behaviour.

Script should also account for the following situations:

a : at the beginning of the list is the same as a . at the beginning of the "list" (:/bin is the same a .:/bin)
a :: any where in the list is the same as :.: (/bin::/etc is the same as (/bin:.:/etc)
a : at the end of the list is the same a :. ( /bin: is the same as /bin:. )

The input to the script will be one or more space separated lists with elements in individual lists separated by colon, and the output will be a single colon separated list with all redundant elements removed.

Examples:

prompt> clean_list a a:b a:b:c :x: y:z
a:b:c:.:x:y:z

prompt>clean_list /bin:/usr/bin:/usr/openwin/bin /usr/bin:/usr/etc:/etc: /usr/bin/X11 .:/bin
/bin:/usr/bin:/usr/openwin/bin:/usr/etc:/etc:.:/usr/bin/X11

prompt>clean_list apple:orange:apple pear orange peach
apple:orange:pear:peach

Purchase this Solution

Solution Summary

Script given in solution does not use any temporary files, and is reasonably commented. It also defines and uses shell functions for better readability and understandability. Script has been well tested for the given examples and few extra boundary cases.

Solution Preview

Please rename attached 151588.sh to clean_list.sh before you run it. Script has been tested for the given ...

Purchase this Solution


Free BrainMass Quizzes
Java loops

This quiz checks your knowledge of for and while loops in Java. For and while loops are essential building blocks for all Java programs. Having a solid understanding of these constructs is critical for success in programming Java.

Basic UNIX commands

Use this quiz to check your knowledge of a few common UNIX commands. The quiz covers some of the most essential UNIX commands and their basic usage. If you can pass this quiz then you are clearly on your way to becoming an effective UNIX command line user.

Excel Introductory Quiz

This quiz tests your knowledge of basics of MS-Excel.

Basic Networking Questions

This quiz consists of some basic networking questions.

Word 2010: Table of Contents

Ever wondered where a Table of Contents in a Word document comes from? Maybe you need a refresher on the topic? This quiz will remind you of the keywords and options used when working with a T.O.C. in Word 2010.