Help with a shell script to concatenate lists together


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Help with a shell script to concatenate lists together
# 1  
Old 07-05-2007
Help with a shell script to concatenate lists together

Below is a description of what im trying to achieve:

Write a shell script to concatenate lists together, and output the resulting list. Do not include any argument that is a sub-list of the entire list. (The script will clean the list of any redundant items.) You must preserve the original order of the list. Remember to 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 colon or space separated lists and the output will be a single colon separated list with all redundant items removed.

Examples:

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

prompt>clean_list appleSmilierange:apple pear orange peach
appleSmilierangeSmilieearSmilieeach

The following code is where im at right now but i'm not quite getting the desired results. for example, when i try the first example above i get a result of aSmiliec:x:y:z (not the aSmiliec:.:x:y:z)

#!/bin/sh

for P in `echo $* | sed -e 's/^:/.:/' -e 's/::/:.:/' -e 's/:$/:./' -e 's/:/ /g'`

do
case $NP in

"") NP="$P"
;;

$P|$P:*|*:$P:*|*:$P) continue
;;

*) NP="$NP:$P"
;;

esac

done

echo $NP

Any suggestions are appreciated!!!!!
# 2  
Old 07-05-2007
Read the rules. Homework questions are not permitted. Thread closed.
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

• Write a shell script that upon invocation shows the time and date and lists all the logged-in user

help me (1 Reply)
Discussion started by: sonu pandey
1 Replies

2. UNIX for Advanced & Expert Users

Concatenate output in shell script

Hi Colleagues, I need the help in the followind. I execute this. select count(*) from schema.tablew the output is this. select count(*) from schema.table 3955 I need the followind output. select count(*) from schema.table 3955 Thank you for you help. (8 Replies)
Discussion started by: systemoper
8 Replies

3. UNIX for Advanced & Expert Users

Concatenate lines in file shell script

Hi colleagues, I have a file in this format. "/cccc/pppp/dddd/ggg/prueba.txt". ERROR" THE error bbbbbbbbbb finish rows. "/kkkk/mmmm/hhhh/jjj/ejemplo.txt". ERROR This is other error rows.I need my file in this format. "/cccc/pppp/dddd/ggg/prueba.txt". ERROR" THE error bbbbbbbbbb finish rows.... (3 Replies)
Discussion started by: systemoper
3 Replies

4. Shell Programming and Scripting

Shell script that lists files with different owner than the folder

Hello, I'm trying to write a script which is listing files based on different preferences, like filetype or permissions. All is fine, except for one: I want to list files in /home which has a different owner than the home directory it is in. Here is an example: /home/UserA is the directory, and... (10 Replies)
Discussion started by: Zwiebi
10 Replies

5. Shell Programming and Scripting

C shell: Working with lists

Hello Unix Gurus, I have: A list of parameters that repeat (in .txt file) Example: params.txt Series: XYZ Manufacturer: ... Software Version: ... Year made: ... Series Series: XYZ Manufacturer: ... Software Version: ... Year made: ... Series Series: ABC Manufacturer: ... ... (7 Replies)
Discussion started by: lapiduslost
7 Replies

6. Shell Programming and Scripting

Shell Script to Create non-duplicate lists from two lists

File_A contains Strings: a b c d File_B contains Strings: a c z Need to have script written in either sh or ksh. Derive resultant files (File_New_A and File_New_B) from lists File_A and File_B where string elements in File_New_A and File_New_B are listed below. Resultant... (7 Replies)
Discussion started by: mlv_99
7 Replies

7. Shell Programming and Scripting

Editing lists of integers in 1d files with bash shell

Hi, I need a script that will: 1. Go through about 20 different folders, each containing about 20 1d files. The 1d files go something like this: 22.253 37.707 78.117 112.374 127.944 156.067 180.956 233.785 249.256 ... (1 Reply)
Discussion started by: ac130pilot
1 Replies

8. Shell Programming and Scripting

How to cut, concatenate data in Shell Script

Hello All,, I'm very new to Unix and I'm more in SAP ABAP. I have a requirement for a shell script which will accept one parameter as Input file name(with directory) e.g : /sapdata/deubank/dbdirect/out/deu01deupe/in/deu01deupe20051207111320.pmt In the shell script I have to make two more... (2 Replies)
Discussion started by: vasan_srini
2 Replies

9. Shell Programming and Scripting

Check lists for Unix Shell Programming

Hi all, Can anyone provide me any checklists or a list of steps I should follow before executing my scripts. Could also tell me if there are any other standards to be followed while shell programming like naming conventions for variables etc. Your help would be much appreciated. Regards,... (2 Replies)
Discussion started by: srikanth_ksv
2 Replies

10. Shell Programming and Scripting

Failed to concatenate parameter in k-shell

Hi folks, I'm trying to concatinate a time zone offset parameter to the word "GMT" and i failed. I have the following function: update_opmn_xml() { echo "\nChecking opmn.xml ..." ## Calculating timezone offset calc_timezone_offset echo ${TzOffset} export opmnXml=/tmp/opmn.xml... (1 Reply)
Discussion started by: nir_s
1 Replies
Login or Register to Ask a Question