Running a diff on all pairs of arguments

Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Running a diff on all pairs of arguments
# 1  
Old 02-10-2014
Running a diff on all pairs of arguments

I would like to create a loop and an inner loop to do a diff command on each pair of files passed as arguments. For example, if four files were on the command line, a diff would run on 1-2, 1-3, 1-4, 2-3, 2-4, & 3-4. Thus far I know the $# will give the count of the arguments and argv (instead of shift) would be used to refer to each argument, but I don't know how to define or modify variables which would be used as subscripts.

# 2  
Old 02-10-2014
What operating system and shell are you using?

Most of us avoid csh when writing scripts, but your reference to argv doesn't sound like you are using a shell based on Bourne shell syntax.
# 3  
Old 02-10-2014
Use two nested for loops, the outer running var_i from 1 to $#-1, the inner running var_j from var_i+1 to $#. You then need eval to run the diff command inside the loops:
eval diff \$$var_i \$$var_j

# 4  
Old 02-11-2014
It's SCO Unix and I believe it uses the Bourne Shell.
# 5  
Old 02-11-2014
If it doesn't have a Bourne shell it's not UNIX.

I don't think you need eval for this:


IFS="^" # Needs to be some char not present in your input

while [ ! -z "$REST" ]
        while [ "$#" -ne - 0 ]
                echo diff "$FIRST" "$1"

        set -- $REST

Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. UNIX for Beginners Questions & Answers

Running local script remotely with arguments

Dear Experts, I have found this script on internet that can be used to execute local script remotely #!/bin/bash # # usage: localscript remoteuser remotehost arg1 arg2 ... realscript=$1 user=$2 host=$3 shift 3 # escape the arguments declare -a args ... (4 Replies)
Discussion started by: mukulverma2408
4 Replies

2. Shell Programming and Scripting

Need to pass arguments while running a Shell Script

Shell Script Gurus, I am writing a shell script which needs User ID's to pass as an Arguments in command line while executing. Can this be doable? I've never done this, If you give a sample script that would be helpful, Thanks. (1 Reply)
Discussion started by: shekar777
1 Replies

3. Shell Programming and Scripting

Diff 3 files, but diff only their 2nd column

Guys i have 3 files, but i want to compare and diff only the 2nd column path=`/home/whois/doms` for i in `cat domain.tx` do whois $i| sed -n '/Registry Registrant ID:/,/Registrant Email:/p' > $path/$i.registrant whois $i| sed -n '/Registry Admin ID:/,/Admin Email:/p' > $path/$i.admin... (10 Replies)
Discussion started by: kenshinhimura
10 Replies

4. Shell Programming and Scripting

Passing arguments while running the script

Hi, I have a requirement for creating a MQ (queue) where the inputs has to be passed as arguments. Running the script as below ./ "Servername" "QueueManagername" "QueuecreationCommand" cat echo "Welcome to $1" runmqsc $2 < $3 But the queue creation command is... (9 Replies)
Discussion started by: Anusha M
9 Replies

5. Shell Programming and Scripting

Running local script remotely with arguments in ksh

When i use ssh command to execute local script on remote server , I am unable to do it. Please let me know how this can be done in ksh req=abc dte=ghd ssh username@hostname "$req $dte" < (2 Replies)
Discussion started by: lalitpct
2 Replies

6. Shell Programming and Scripting

keep only pairs

Hi, I am trying to paste together two files which are like this- 1 2 4 and 2 3 4 The paste command would work by default for this case, but when there are cases where the number of entries are different in each file. for eg: 1 3 and 1 3 4 I want to make it such that the odd... (11 Replies)
Discussion started by: jamie_123
11 Replies

7. Shell Programming and Scripting

serach diff filename in diff location using shell scripting

Hi, I am new to shell scripting. please help me to find out the solution. I need a script where we need to read the text file(consists of all file names) and get the file names one by one and append the date suffix for each file name as 'yyyymmdd' . Then search each file if exists... (1 Reply)
Discussion started by: Lucky123
1 Replies

8. Shell Programming and Scripting

.procmailrc and uudeview (put attachments from diff senders to diff folders)

Moderator, please, delete this topic (1 Reply)
Discussion started by: optik77
1 Replies

9. Shell Programming and Scripting

Simulate SVN diff using plain diff

Hi, svn diff does not work very well with 2 local folders, so I am trying to do this diff using diff locally. since there's a bunch of meta files in an svn directory, I want to do a diff that excludes everything EXCEPT *.java files. there seems to be only an --exclude option, so I'm not sure... (3 Replies)
Discussion started by: ackbarr
3 Replies

10. Shell Programming and Scripting

diff 2 files; output diff's to 3rd file

Hello, I want to compare two files. All records in file 2 that are not in file 1 should be output to file 3. For example: file 1 123 1234 123456 file 2 123 2345 23456 file 3 should have 2345 23456 I have looked at diff, bdiff, cmp, comm, diff3 without any luck! (2 Replies)
Discussion started by: blt123
2 Replies
Login or Register to Ask a Question