|
|
|
|
google site
|
|||||||
| Forums | Register | Blog | Man Pages | Forum Rules | Links | Albums | FAQ | Users | Calendar | Search | Today's Posts | Mark Forums Read |
| Shell Programming and Scripting Post questions about KSH, CSH, SH, BASH, PERL, PHP, SED, AWK and OTHER shell scripts and shell scripting languages here. |
![]() |
|
|
Thread Tools | Search this Thread | Rate Thread | Display Modes |
|
|||
|
Comparing Arrays?
Is there anyway that I can compare two Arrays to see if any new strings have been added in them? eg:
Array 1: Joe Bob Jane Array 2: Joe Bob Jane Greg It would then output a new array with the changes: Array 3: Greg I'm not very good at shell scripting, and my google and forum searches have come up empty. I'd rather do the whole thing in bash, because this will be run on OSX, and you don't really get much else than bash unless you install developer tools, and the computers that I intend to use the script on will not have the develope tools. Thanks in advance! |
| Sponsored Links | ||
|
|
|
|||
|
The problem with that is that if I try to do this (which is what will end up happening): Code:
#!/bin/sh
a1="Joe Bob Jane"
a2="Joe Bob Jack Jane Greg"
a3=${a2#$a1}
echo $a3The output I get is this: Code:
Joe Bob Jack Jane Greg And I need it to only return the words in the second string that weren't in the first, which is why I thought arrays would be better. |
|
|||
|
Code:
ruby -e 'puts (ARGV.last.split -
ARGV[-2].split).join(" ")' "foo bar" "zed foo bar zab"
zed zabCode:
newlisp -e '(silent)(println (join (difference (parse (last (main-args))) (parse (nth -2 (main-args)))) " "))' "foo bar" "zed foo bar zab" zed zab The newlisp executable, which is all you need, is about 170kb on my machine. You could put it on a floppy or a flash drive. |
| Sponsored Links |
|
|
![]() |
| Bookmarks |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|
More UNIX and Linux Forum Topics You Might Find Helpful
|
||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| Need Help with awk and arrays | fusionX | Shell Programming and Scripting | 7 | 02-11-2008 06:41 PM |
| awk arrays | imonthejazz | Shell Programming and Scripting | 1 | 09-21-2007 10:29 AM |
| arrays in awk??? | craigsky | Shell Programming and Scripting | 3 | 08-27-2007 10:13 PM |
| KSH and arrays | whited05 | Shell Programming and Scripting | 1 | 06-24-2005 01:07 PM |
| Two or more arrays in Awk | nitin | UNIX for Advanced & Expert Users | 1 | 12-10-2001 09:37 PM |