The UNIX and Linux Forums  

Go Back   The UNIX and Linux Forums > Top Forums > Shell Programming and Scripting
.
google unix.com



Shell Programming and Scripting Post questions about KSH, CSH, SH, BASH, PERL, PHP, SED, AWK and OTHER shell scripts and shell scripting languages here.

More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
Script to concatenate several files docaia Shell Programming and Scripting 3 02-03-2008 09:07 AM
How to cut, concatenate data in Shell Script vasan_srini Shell Programming and Scripting 2 12-07-2005 04:41 AM
How to concatenate two strings or several strings into one string in B-shell? fontana Shell Programming and Scripting 2 08-26-2005 12:58 PM
Check lists for Unix Shell Programming srikanth_ksv Shell Programming and Scripting 2 08-08-2005 07:40 AM
Failed to concatenate parameter in k-shell nir_s Shell Programming and Scripting 1 05-23-2005 06:52 AM

 
English Japanese Spanish French German Portuguese Italian Dutch Swedish Russian Norwegian Hungarian Hebrew Danish Bulgarian Greek Powered by Powered by Google
 
LinkBack Thread Tools Search this Thread Rate Thread Display Modes
Prev Previous Post   Next Post Next
  #1 (permalink)  
Old 07-05-2007
rfourn rfourn is offline
Registered User
  
 

Join Date: Jun 2007
Posts: 4
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 ac :x: y:z
ac:.:x:y:z

prompt>clean_list applerange:apple pear orange peach
applerangeeareach

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 ac:x:y:z (not the ac:.: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!!!!!
 

Bookmarks

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On




All times are GMT -4. The time now is 07:35 AM.


Powered by: vBulletin, Copyright ©2000 - 2006, Jelsoft Enterprises Limited. Language Translations Powered by .
vBCredits v1.4 Copyright ©2007 - 2008, PixelFX Studios
The UNIX and Linux Forums Content Copyright ©1993-2009. All Rights Reserved.Ad Management by RedTyger

Content Relevant URLs by vBSEO 3.2.0