Using sdiff without files


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Using sdiff without files
# 1  
Old 11-13-2012
Using sdiff without files

Hi,

I'm trying to use sdiff by parsing the output of another command instead of the filename:
Code:
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:
Code:
~$ diff <(echo test1) <(echo test2)
1c1
< test1
---
> test2

Is there a way to use sdiff like I use diff in this example?

Thanks
# 2  
Old 11-20-2012
If you check out sdiff using strace/truss/tusc, you can see where it goes wrong. This tool is very educational, turn on all the local options, and learn! Probably, it does seeks and so gets upset at the pipes. Try it with temp files.
This User Gave Thanks to DGPickett For This Post:
# 3  
Old 11-21-2012
Thanks for the reply DGPickett,

Unfortunately I can't use strace on this machine (unable to open /dev/log) and truss gives me a bunch of:
Code:
write(1, "\n", 1)                               = 1
read(3, 0x08066234, 5120)                       = 0

Nevertheless, it's probably a very useful tool which I can and will use for other problems
# 4  
Old 11-21-2012
Hi.

For this system:
Code:
OS, ker|rel, machine: Linux, 2.6.26-2-amd64, x86_64
Distribution        : Debian GNU/Linux 5.0.8 (lenny) 
bash GNU bash 3.2.39
sdiff (GNU diffutils) 2.8.1

I get this:
Code:
sdiff <(echo test1) <(echo test2)sdiff <(echo test1) <(echo test2)
test1							      |	test2

The strace with first line:
Code:
strace sdiff <(echo test1) <(echo test2)
execve("/usr/bin/sdiff", ["sdiff", "/dev/fd/63", "/dev/fd/62"], [/* 48 vars */]) = 0

Best wishes ... cheers, drl
# 5  
Old 11-21-2012
Yes, that is what strace/tusc/truss do, they give you all the system calls and their results, and sometimes other library calls can be selected. On Solaris, -u'*' says show every user lib call, so you can see everything not a macro: fgets, printf, strchr, etc. And you do not need source code, or to set anythig before it starts running, to peek at what is going on, you can attach with -p PID. In some cases, I need to see the launch, so I call it like this:
Code:
$ ( sleep 2
   test-comand-line
 )& truss ... -o /tmp/xxx.tr -p $!

To just take a peek, run the truss output (defaults to stderr) into a head command and just sample N lines. When truss cannot write, it detaches and exits. Thigs do run slower with truss attached, as it instructs the kernel to stall the target while it tells truss what it is up to.

This is a wonderfully educational and stupendously powerful tool. Play with it.

My tusc of hpux 11.00 trace says it opens the pipes and then passes their names to diff -b, which also opens them. Named pipes opened once for write do not open twice for read, they hang awaiting the second open for write. The shell named pipes /dev/fd/### are, if anything, even less interested in a second open() of any sort, and that fd number may be occupied by another file after the fork and exec and all such nonsense. So, not pipe friendly, and the sad thing is that sdiff does a stat of the pipe name before opening it, but ignores that it is a pipe. Then diff -b does seeks and ignores the errors.

Last edited by DGPickett; 11-21-2012 at 05:34 PM..
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. UNIX for Beginners Questions & Answers

Sdiff

file1: USER:XACME\cn3937 User:XACME\z01220 User:XACME\z01404 User:XACME\z02102 User:XACME\U17234 File2: USER:XACME\lawson USER:XACME\cn7913 USER:XACME\cn8037 USER:XACME\cn8042 USER:XACME\cn8046 USER:XACME\u31645 USER:XACME\u19050 USER:XACME\U28715 USER:XACME\U17234 USER:XACME\cn3937... (2 Replies)
Discussion started by: loktamann
2 Replies

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

3. Shell Programming and Scripting

Sdiff command

Hi i am comparing file on 2 different machine with the help of script. however i am get below o/p ======= /usr/tmp ========= ======= /usr/tmp not a regular file i am not sure what does "not a regular file mean" . is it something serious, if yes then what i need to check or we can... (1 Reply)
Discussion started by: scriptor
1 Replies

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

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

6. Shell Programming and Scripting

Sdiff query

I wanted to ask can sdiff be used for comparing files which are present in different network?? If yes then how? Thanks in Advance!!!!!!! (1 Reply)
Discussion started by: bhavanabahety
1 Replies

7. Shell Programming and Scripting

sdiff discrepancies

Hi All I have two large (similar) files that have a unique number in the first column...(the trade id) and then a value for that trade in the second column...delimited by "~". Here is a snippet of what the files look like 10030372~-410682.73 10030490~-4052867.73 10030646~-352592.21... (8 Replies)
Discussion started by: kbuttz
8 Replies

8. UNIX for Dummies Questions & Answers

A more intelligent SDIFF

Hi all I have two files which are essentially the same. However the way an exponent is written is different (i.e. in 1 file, a particular number might be written as 1.43230000E+02 whereas in another it might be 1.4323E2). If I use SDIFF then the program will merely check the ASCII characters... (1 Reply)
Discussion started by: robbiegregg
1 Replies

9. UNIX for Dummies Questions & Answers

Sdiff ? problem

Hello, I'm using Sdiff to compare 2 files, I've used this before and it works fine and still does in some cases. But it seems to trip up when using combinations of alpha-numeric text. I created two simple files to test and as you can see it seems to trip up on the "gr55a" text, any ideas ? ... (2 Replies)
Discussion started by: cowpoke
2 Replies

10. Shell Programming and Scripting

sdiff problem

Hi, I'm having the following problem with the unix sdiff command. for example if I try sdiff <filename 1> <filename 2> Where filename 1 and filename 2 contain really long pathnames that I need to compare. The output I get will be 139 characters long which is the default. But an output of... (0 Replies)
Discussion started by: ruudrio
0 Replies
Login or Register to Ask a Question