Sdiff doesn't try and compare to closest match


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Sdiff doesn't try and compare to closest match
# 1  
Old 02-27-2017
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:

Code:
sdiff sourceFileNames targetFileNames
17021701P.blf | 17021901P.ibk
17021701P.chn | 17021901P.irk
17021701P.bmr | 17021901P.dyd
17021701P.dpf | 17021901P.blf
17021701P.dpi | 17021901P.blr
17021701P.drk | 17021901P.bmr
17021701P.gcd | 17021901P.dpf
17021701P.gcm | 17021901P.dpi
17021701P.gcp | 17021901P.drk
17021701P.gcr | 17021901P.gcd
17021701P.idx | 17021901P.stb
17021701P.ltm | 17021901P.stf
17021701P.mfd | 17021901P.tna
17021701P.ipf | 17021901P.gcm
17021701P.mgr | 17021901P.gcp
17021701P.mrl | 17021901P.gcr
17021701P.stb | 17021901P.idx
17021701P.stf | 17021901P.ltm
17021701P.tna | 17021901P.mfd
17021701P.ibk | 17021901P.ipf
16021701P.irk | 17021901P.mgr
17021701P.dyd | 17021901P.mrl



Moderator's Comments:
Mod Comment Please use CODE tags as required by forum rules!

Last edited by RudiC; 02-27-2017 at 01:21 PM.. Reason: reinstated the original text
# 2  
Old 02-27-2017
There is no 'strip file extensions then compare' utility that I know of. You may have to make the data match for a diff utility to count it as a match.

Code:
awk -F"." '{ print $1 > OUT }' OUT="/tmp/file1" sourceFileNames OUT="/tmp/file2" targetFileNames
sdiff /tmp/file1 /tmp/file2
rm -f /tmp/file1 /tmp/file2

# 3  
Old 02-27-2017
If compared line by line, none of your extensions would match. With a recent shell providing "process substitution" you could try
Code:
sdiff <(cut -d. -f2 file1 | sort) <(cut -d. -f2 file2 | sort)
blf                                blf
                                  >    blr
bmr                                bmr
chn                                  <
dpf                                dpf
dpi                                dpi
drk                                drk
dyd                                dyd
.
.
.

# 4  
Old 02-27-2017
Hi.
Quote:
Originally Posted by jamilpasha
In the example below i would want the extensions to match.
Did you mean ignore rather than match?

If so there are utilities that allow mis-matches, e.g. agrep, cgrep, which could be useful.

However, if the expected output had been posted, it would probably have answered questions like this. Please do so now and in the future.

Best wishes ... cheers, drl
# 5  
Old 02-27-2017
Thank you for the prompt response guys!! I appreciate all your help!!

I must have been little clear on my requirement and output that I am expecting!!

I was writing a script to compare the files using sdiff or comp utility!! Before doing that I wanted the script to be generic where user can update a config file which expects the file name patterns (ex- file starts with 20170212 and end with .txt) This would be one set which I would call source. Similarly the config to be updated with file start and end patter for target. (ex- 20170213 and ends with .txt)

I may get following files in the list-

Source-
Code:
20170212abc.txt
20170212xyz.txt
20170212jam.txt

Target-
Code:
20170213abc.txt
20150213xyz.txt (2015 intentional)
20170213pas.txt

Without expecting users to do a mapping manual to do a comparison of these files. I would want to map them based on nearest match and run the comparison.

Expected map-

Code:
20170212abc.txt --> 20170213abc.txt
20170213xyz.txt --> 20150213xyz.txt
20170212jam.txt --> Missing
Missing --> 20170213pas.txt

Hope I was able to explain my requirement!!

You guys are awesome!! Thanks again!!


Moderator's Comments:
Mod Comment Please use CODE tags as required by forum rules!

Last edited by RudiC; 02-27-2017 at 01:26 PM.. Reason: Added CODE tags.
# 6  
Old 02-27-2017
Please DON'T edit posts (here: post#1) after people have answered pulling the rug from under their feet! And, seriously, start using code tags!

What is a nearest match in your definition? Do you want to ignore digits and compare the alphabtic part of the file names?
# 7  
Old 02-27-2017
Quote:
Originally Posted by RudiC
Please DON'T edit posts (here: post#1) after people have answered pulling the rug from under their feet! And, seriously, start using code tags!

What is a nearest match in your definition? Do you want to ignore digits and compare the alphabtic part of the file names?
---------- Post updated at 12:34 PM ---------- Previous update was at 12:31 PM ----------

@RudiC- sorry for editing the original post!! It was for a reason!!

I'm new here and will ensure to use code tags wherever applicable..

Nearest match to me would be looking at some specific string in the file names that are common! Like the one I explained in above example..

While I am trying to work on a generic utility that can work across projects I do not want to create an additional filters to exclude and match!! Hope I was able to answer your query!!
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Linux

Ssh key doesn't match

I'm loged on server A as user infa8. I want to login via ssh key on server B as user ussdsc. destination server (B) is a redHat 6.2. Permissions for ussdsc@B for home, ssh and authorized_keys: $ ls -ltr | grep ussdsc drwxr-xr-x. 29 ussdsc mobifon 4096 Feb 18 11:43 ussdsc $ getfacl... (8 Replies)
Discussion started by: black_fender
8 Replies

2. UNIX for Dummies Questions & Answers

Compare data - Match first column and compare second

Hi guys, looking for some help with a way to compare data in two files but with some conditions. example, File 1 consists of site1,10.1.1.1 site2,20.2.2.2 site3,30.3.3.3 File 2 contains site1,l0.1.1.1 site2,50.1.1.1 site3,30.3.3.3 site4,40.1.1.1 I want to be able to match the... (1 Reply)
Discussion started by: mutley2202
1 Replies

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

4. Shell Programming and Scripting

Script to compare files recursively using sdiff

Hi All, I have been surfing to get some idea on how to compare same files from two different paths. one path will have oldfiles directory and another path will have newfiles directory. Each main directories will have sub-directories in them and each sub-directories inturn will have... (3 Replies)
Discussion started by: Optimus81
3 Replies

5. Shell Programming and Scripting

Swap usage by top and free command doesn't match

Its rather confusing, the output of top command is below: The "swap" field of top is described by the manpage as: "The swapped out portion of a task's total virtual memory image." But the output of free command suggests something else and it does tally with the output of swapon... (3 Replies)
Discussion started by: proactiveaditya
3 Replies

6. Solaris

Error: svcs: Pattern 'pooladm.conf' doesn't match any instances

Hi, I got the following errors during zfs resource pool configuration. Please help. Thanks. # svcs *pool* svcs: Pattern 'pooladm.conf' doesn't match any instances STATE STIME FMRI # svcadm enable system/pools:default # svcs *pool* svcs: Pattern 'pooladm.conf' doesn't match any... (4 Replies)
Discussion started by: aixlover
4 Replies

7. UNIX for Advanced & Expert Users

sed match closest/nearest pattern

All i am struggling to raplace some text in a line between two (closest) patterns , line="/home/usr/bin/:/home/usr/devuser,n1.9/bin:/home/usr/root/bin" i want to replace "devuser,n1.9" with "NEWVAL", basically all teh text from "devuser" until nearest '/' with some new text. i tried teh... (1 Reply)
Discussion started by: sudheer1984
1 Replies

8. Shell Programming and Scripting

compare/match arrays

Hi there all, I am having a question. Is it posible to compare elements of 2 different arrays? For example I got Array 1 | Array 2 123_abc | 123_bcd 123_bcd | 234_bcd 234_abc | 567_abc 234_bcd | 123_abc than the match is 123_abc & 234_bcd and non of the others. So... (3 Replies)
Discussion started by: draco
3 Replies

9. UNIX for Dummies Questions & Answers

My output doesn't match anything...and the program is pretty simple

This is what I have: #include <stdio.h> int main (void) { int integerVar; int floatingVar; int doubleVar; int charVar; integerVar = 100; floatingVar = 331.79; doubleVar = 8.44e+11; charVar = 'W'; _Bool boolVar; boolVar = 0; ... (3 Replies)
Discussion started by: pwanda
3 Replies

10. UNIX for Dummies Questions & Answers

echo $PATH doesn't match $HOME/.profile

This is on a Solaris 9 box, but I feel like a noob, so I am posting here. When I echo $PATH I get a lot of duplicate paths and extra stuff I don't need. What I want is just what I set up in my home dir under .profile My login shell=/bin/bash I checked the following and there are no path... (1 Reply)
Discussion started by: Veestan
1 Replies
Login or Register to Ask a Question