bash script help - Linux
This is a discussion on bash script help - Linux ; hello-
I have two variables for a bash script and somehow not sure how to
resolve it.... in a short version of lines....
newcity="london cairo newyork"
oldcity="cairo congo paris london"
Is there a easiser way to find:
1) common cities,
...
-
bash script help
hello-
I have two variables for a bash script and somehow not sure how to
resolve it.... in a short version of lines....
newcity="london cairo newyork"
oldcity="cairo congo paris london"
Is there a easiser way to find:
1) common cities,
2) unique to newcity
3) unique to oldcity
thanks
hallian
-
Re: bash script help
On 14 Apr 2004 19:24:41 -0700, hallian wrote:
> I have two variables for a bash script and somehow not sure how to
> resolve it.... in a short version of lines....
>
> newcity="london cairo newyork"
> oldcity="cairo congo paris london"
>
> Is there a easiser way to find:
> 1) common cities,
If [ $oldcity = $newcity ] ; then
it's common
fi
> 2) unique to newcity
> 3) unique to oldcity
You did not give number of cities to check.
Put new cities into new.txt
Put old cities into common.txt
Now as you get each city, you can grep the txt files to determin which
is which.
-
Re: bash script help
hallian wrote:
> hello-
>
> I have two variables for a bash script and somehow not sure how to
> resolve it.... in a short version of lines....
>
> newcity="london cairo newyork"
> oldcity="cairo congo paris london"
>
> Is there a easiser way to find:
> 1) common cities,
> 2) unique to newcity
> 3) unique to oldcity
>
> thanks
> hallian
man comm
--
William Park, Open Geometry Consulting,
Linux solution/training/migration, Thin-client
-
Re: bash script help
(I feel like I'm doing somebody's homework assignment)
Here's one way, but it's not easy or short IMHO:
#!/bin/bash
newcity="london cairo newyork"
oldcity="cairo congo paris london"
read -a newcityarray < <(echo $newcity)
read -a oldcityarray < <(echo $oldcity)
typeset -i i=0
typeset -i j
typeset -a common
typeset -a uniqueToNew
typeset -a uniqueToOld
while ((i<${#newcityarray[*]}))
do
j=0
while ((j<${#oldcityarray[*]}))
do
if [[ ${newcityarray[$i]} = ${oldcityarray[$j]} ]]
then
common=(${common[*]} ${oldcityarray[$j]})
fi
((j=j+1))
done
if [[ ${newcityarray[$i]} != ${common[${#common[*]}-1]} ]]
then
uniqueToNew=(${uniqueToNew[*]} ${newcityarray[$i]})
fi
((i=i+1))
done
i=0
while ((i<${#oldcityarray[*]}))
do
j=0
isCommon="FALSE"
while ((j<${#common[*]}))
do
if [[ ${oldcityarray[$i]} = ${common[$j]} ]]
then
isCommon="TRUE"
fi
((j=j+1))
done
if [[ "$isCommon" != "TRUE" ]]
then
uniqueToOld=(${uniqueToOld[@]} ${oldcityarray[$i]})
fi
((i=i+1))
done
echo -e "Common Cities: ${common[*]} \nUnique to new: ${uniqueToNew[*]}"
echo "Unique to old: ${uniqueToOld[*]}"
-
Re: bash script help
On Fri, 30 Apr 2004 00:42:57 GMT, news-david.IHATESPAM@wizNOSPAMdoNOTSPAMm.net wrote:
>
> (I feel like I'm doing somebody's homework assignment)
I think so also.
Please bookmark the following, very large,
Frequently Asked Questions (faq) Search engine:
http://groups.google.com/advanced_group_search
oldcity newcity in the first box
*linux* in Newsgroup, U need 2 use *, pick English
Results 1 - 2 of about 4 English messages for oldcity newcity
group:*linux*. (0.23 seconds)