Help with Script: If diff between files is nothing then set a variable


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Help with Script: If diff between files is nothing then set a variable
# 1  
Old 11-18-2008
Help with Script: If diff between files is nothing then set a variable

how about a script that compares 2 files using diff (or similar) and if they are then same then set a variable, v1=int else v1=0.

thanks
# 2  
Old 11-18-2008
Use diff exit code
Code:
diff file1 file2 > /dev/null
v1=$?
echo $v1

# 3  
Old 11-18-2008
thanks this is very useful for what i want to do Smilie
Login or Register to Ask a Question

Previous Thread | Next Thread

9 More Discussions You Might Find Interesting

1. 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

2. Shell Programming and Scripting

Help needed with shell script to search and replace a set of strings among the set of files

Hi, I am looking for a shell script which serves the below purpose. Please find below the algorithm for the same and any help on this would be highly appreciated. 1)set of strings need to be replaced among set of files(directory may contain different types of files) 2)It should search for... (10 Replies)
Discussion started by: Amulya
10 Replies

3. Shell Programming and Scripting

Script for Diff b/w 2 CSV files

Hello friends, I have two CSV files.. I am looking to create a script which automatically 'diff' between those 2 csv files each month..Can anyone help me in creating the automatic script which will find the differences between 2 csv files. Appreciated your help. Thanks. (4 Replies)
Discussion started by: bobby1015
4 Replies

4. Shell Programming and Scripting

diff script to copy files to other dir when not exists

I have two directories that are mostly the same: dir1 dir2 Is there an easy way to take the output of diff and copy files from dir1 that do not exist in dir2 - but copy them to the same path (many nested directories). am only trying to copy files in dir1 that do not exist in dir2. ... (5 Replies)
Discussion started by: jvsrvcs
5 Replies

5. UNIX for Dummies Questions & Answers

Diff script for 2 files.

Hi all, I am stuck up in middle of a process. I have 2 files A and B. Some lines in A are commented with either // or /* */ But basically content (uncommented portion) of both the files are same. Now I want to prove that both the files are same using some script. I can't do a diff as... (1 Reply)
Discussion started by: bishnu.bhatta
1 Replies

6. Shell Programming and Scripting

compare 2 coloum of 2 diff files using perl script

Hi, i am new to perl scripting.. i am still learing it.. i am asked to write a perl script which should compare 2 coloums of 2 different files. if those 2 coloumn are same the script should store the both the lines in 2 diff files. these are files, file 1: 21767016 226112 char 19136520... (3 Replies)
Discussion started by: vasuki
3 Replies

7. Shell Programming and Scripting

Check if variable is set in script

I want to check to see if a variable is set - and if not set it to something ie. variable name test I want to check if $test is set then if there is nothing set against this currently - then set it to 0 Whats the best / shortest way of doing this in a script? (3 Replies)
Discussion started by: frustrated1
3 Replies

8. Shell Programming and Scripting

Getting value of variable set in subprocess script

I am writing a shell script that executes another script by fetching it over the network and piping its contents into sh (ftp -o - $script | sh; or wget -O - |sh). Since this bypasses putting the script on the filesystem, this means I can't source the script directly (using . ), but rather it... (1 Reply)
Discussion started by: hadarot
1 Replies

9. 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