Sponsored Content
Top Forums Shell Programming and Scripting Script to compare files recursively using sdiff Post 302790635 by hanson44 on Saturday 6th of April 2013 05:40:19 AM
Old 04-06-2013
You stated it pretty clearly. It's just rather complex and tedious.

Here's a working version that does basically what you want, as best I can understand. It does not put the results in each directory, but all together in one file. Putting the results in different directories would complicate the script, and it seems having one results file might be easier to use? I think you could modify the script to add other details as needed. I think the script is pretty clear. It uses simple commands, but is just kind of tedious. Let me know if any questions.
Code:
$ cd /tmp
$ ls -R oldfiles newfiles
newfiles:
subdirA  subdirB

newfiles/subdirA:
subA.txt

newfiles/subdirB:
subB.txt

oldfiles:
subdirA  subdirB  subdirC

oldfiles/subdirA:
subA.txt

oldfiles/subdirB:
subB.txt

oldfiles/subdirC:
subC.txt

Code:
$ cat sdiff.sh
# cmp_dir - program to compare two directories

if [ $# -ne 2 ]; then
  echo "usage: $0 old_dir new_dir" 1>&2; exit 1
fi

if [ ! -d "$1" ]; then
  echo "$1 is not a directory!" 1>&2; exit 1
fi

if [ ! -d "$2" ]; then
  echo "$2 is not a directory!" 1>&2; exit 1
fi

rm -f resultfile.txt
missing=0
old_dir="$1" new_dir="$2"
find "$old_dir" -name '*.txt' -print > /tmp/old_paths.x;
while read old_path; do
  echo "old_path = $old_path" >> resultfile.txt
  filename=`basename "$old_path"`
  find "$new_dir" -name "$filename" -print > /tmp/new_path.x
  count=`cat /tmp/new_path.x | wc -l`
  if [ $count -eq 1 ]; then
    new_path=`cat /tmp/new_path.x`
    echo "Comparison with $new_path:" >> resultfile.txt
    sdiff $old_path $new_path >> resultfile.txt
  elif [ $count -gt 1 ]; then
    echo "ERROR: $count found under $new_dir" >> resultfile.txt
  else
    echo "ERROR: does not exist under $new_dir" >> resultfile.txt
    missing=`expr $missing + 1`
  fi
  echo "------------------" >> resultfile.txt
done < /tmp/old_paths.x
echo "Missing: $missing" >> resultfile.txt
echo "File comparision done, please see resultfile.txt"
# echo -n "Press ENTER: "; read; vi resultfile.txt

Code:
$ ./sdiff.sh oldfiles newfiles
File comparision done, please see resultfile.txt

Code:
$ cat resultfile.txt
old_path = oldfiles/subdirB/subB.txt
Comparison with newfiles/subdirB/subB.txt:
Sat Apr  6 01:45:32 PDT 2013                                  | Sat Apr  6 01:44:56 PDT 2013
------------------
old_path = oldfiles/subdirC/subC.txt
ERROR: does not exist under newfiles
------------------
old_path = oldfiles/subdirA/subA.txt
Comparison with newfiles/subdirA/subA.txt:
Sat Apr  6 01:44:36 PDT 2013                                  | Sat Apr  6 01:44:49 PDT 2013
------------------
Missing: 1

 

9 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

script to compare files

HI i wil get input from sql query and that too i can get a list o f files or just one. i have to pick up a file from another directory which hads prefix to this prefix.x.x.x.x.x. And we have to discard prefix and use that file name. we have to compare this file name(no need... (0 Replies)
Discussion started by: pulse2india
0 Replies

2. Shell Programming and Scripting

Shell Script - find, recursively, all files that are duplicated

Hi. I have a problem that i can't seem to resolve. I need to create a script that list all the files, that are found recursively, with the same name. For example if a file exists in more than one directory with the same name it list all the files that he founds with all the info. Could someone... (5 Replies)
Discussion started by: KitFisto
5 Replies

3. Shell Programming and Scripting

Recursively move directories along with files/specific files

I would like to transfer all files ending with .log from /tmp and to /tmp/archive (using find ) The directory structure looks like :- /tmp a.log b.log c.log /abcd d.log e.log When I tried the following command , it movies all the log files... (8 Replies)
Discussion started by: frintocf
8 Replies

4. Shell Programming and Scripting

Problem with script generating files in directory recursively

I have a script which generates recursively some files in folders for a given root folder. I have checks for permissions and it works for all folders except one(i have 777 permission on it). When i try calling the script in problematic folder(problematic folder being root folder), script works as... (2 Replies)
Discussion started by: bb2
2 Replies

5. Shell Programming and Scripting

Using sdiff without files

Hi, I'm trying to use sdiff by parsing the output of another command instead of the filename: sdiff <(echo test1) <(echo test2)However, this seems to cause my terminal session to stop working. If I use it with normal diff it works fine: ~$ diff <(echo test1) <(echo test2) 1c1 < test1... (4 Replies)
Discussion started by: Subbeh
4 Replies

6. Shell Programming and Scripting

Compare 2 files using sdiff command output

Hi All, I have written the shell script which does the following : a. Reads the *.cnf file content from the specified input folder path b. Grep's some strings from the *.cnf file and writes the output in result file(*.cnf_result.txt) in output folder c. Now, if we get new version of... (5 Replies)
Discussion started by: Optimus81
5 Replies

7. Shell Programming and Scripting

Compare two files using awk command recursively

I want to compare two files, 1) Compare Each query result. 2) Compare Only first row of the Query output 3) Compare Time (3rd column), First file time is lesser than 2nd file then print the PO_NUM else do nothing. File1: C:\script>call transaction 1OPOP C:\script>Select ID, PO_ID, TIME, DES... (3 Replies)
Discussion started by: Ragu14
3 Replies

8. Shell Programming and Scripting

SDiff Two files with space problem

Hello guys, I have a problem. I'm trying to use SDiff with two files which are containing spaces. My problem is that I want to save the output with > in an extra file. If I try to use it like this. sdiff "test file1" "test file2" > OutputfileI get this message: usage: diff ... (11 Replies)
Discussion started by: Mariopart
11 Replies

9. Shell Programming and Scripting

Sdiff doesn't try and compare to closest match

In the example below i would want the extensions to match. Is there any other utility or script to achieve this. Kindly help. Example: sdiff sourceFileNames targetFileNames 17021701P.blf | 17021901P.ibk 17021701P.chn | 17021901P.irk 17021701P.bmr | 17021901P.dyd 17021701P.dpf |... (7 Replies)
Discussion started by: jamilpasha
7 Replies
gensprep(8)							 ICU 50.1.2 Manual						       gensprep(8)

NAME
gensprep - compile StringPrep data from files filtered by filterRFC3454.pl SYNOPSIS
gensprep [ -h, -?, --help ] [ -v, --verbose ] [ -c, --copyright ] [ -s, --sourcedir source ] [ -d, --destdir destination ] DESCRIPTION
gensprep reads filtered RFC 3454 files and compiles their information into a binary form. The resulting file, <name>.icu, can then be read directly by ICU, or used by pkgdata(8) for incorporation into a larger archive or library. The files read by gensprep are described in the FILES section. OPTIONS
-h, -?, --help Print help about usage and exit. -v, --verbose Display extra informative messages during execution. -c, --copyright Include a copyright notice into the binary data. -s, --sourcedir source Set the source directory to source. The default source directory is specified by the environment variable ICU_DATA. -d, --destdir destination Set the destination directory to destination. The default destination directory is specified by the environment variable ICU_DATA. ENVIRONMENT
ICU_DATA Specifies the directory containing ICU data. Defaults to /usr/share/icu/50.1.2/. Some tools in ICU depend on the presence of the trailing slash. It is thus important to make sure that it is present if ICU_DATA is set. FILES
The following files are read by gensprep and are looked for in the source /misc for rfc3454_*.txt files and in source /unidata for Normal- izationCorrections.txt. rfc3453_A_1.txt Contains the list of unassigned codepoints in Unicode version 3.2.0.... rfc3454_B_1.txt Contains the list of code points that are commonly mapped to nothing.... rfc3454_B_2.txt Contains the list of mappings for casefolding of code points when Normalization form NFKC is specified.... rfc3454_C_X.txt Contains the list of code points that are prohibited for IDNA. NormalizationCorrections.txt Contains the list of code points whose normalization has changed since Unicode Version 3.2.0. VERSION
50.1.2 COPYRIGHT
Copyright (C) 2000-2002 IBM, Inc. and others. SEE ALSO
pkgdata(8) ICU MANPAGE
18 March 2003 gensprep(8)
All times are GMT -4. The time now is 10:31 AM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy