Check for difference in output of 2 commands?


 
Thread Tools Search this Thread
Top Forums UNIX for Dummies Questions & Answers Check for difference in output of 2 commands?
# 1  
Old 01-21-2011
Check for difference in output of 2 commands?

Hello! I'm just learning the shell, and I would really like to know how to do this:

Given these 2 commands:

ls -l

ls -le

How can I, with a one-liner, ask the shell to show me visually in the shell, what the difference is between the output of the two commands? They look the same to me and I would like the shell to report the difference, if any.

I hope that makes sense. I think this is probably something basic but seems to be a very powerful procedure for future use in comparing other outputs. I don't think I need python for this, which I don't know at all, but it seems like this is a pipe-able procedure within the shell...?

Thank you for your assistance and expertise, TF
# 2  
Old 01-21-2011
In bash/ksh93:
Code:
diff <(ls -l) <(ls -le)

This User Gave Thanks to Scrutinizer For This Post:
# 3  
Old 01-21-2011
FWIW, the man page says:

Code:
 -e         The same as -l, except  displays  time  to  the
                  second,  and  with  one  format  for  all files
                  regardless of age: mmm dd hh:mm:ss yyyy.

# 4  
Old 01-21-2011
Very cool, thanks!

Thanks Scrutinizer! Can you help me understand the output a little better?
[verdepollo, thanks for the assistance, but I meant have the shell report the differences in the outputs of 2 commands, not what does ls -l do or ls -le do].

I used:
diff <(ls -l) <(ls -le)

and got:
"2a3
> 0: group:everyone deny delete
4a6
> 0: group:everyone deny delete
11a14
> 0: group:everyone deny add_file,add_subdirectory,directory_inherit,only_inherit"

Perfect! Thanks very much! I don't quite understand the 2a3, 4a6 and 11a14, but it's pretty much what I was looking for!
# 5  
Old 01-21-2011
What Operating System are you running?
What Shell are you using?

Scrutinizer has quite correctly posted code using the unix "diff" program which is common to all unix versions.
The "diff" program is a buffered context compare program and shows the context of the difference and the address within each file of the difference. It is a very useful tool for comparing files which are similar and where the data is in no particular order. The "<" ">" signs tell you which file the difference came from.
It is very useful for comparing program code. For larger files there are usually special versions of diff supplied like "bdiff".


Let's say we just want to know the differences regardless of which file they came from and with no context and in no order relative to either file. I use this technique a lot for comparing code, but it works equally well for "ls".
Code:
ls -l > /tmp/my_temp_file
ls -le >> /tmp/my_temp_file
cat my_temp_file | sort | uniq -u

(Yes I know I have used "cat". I like left-to-right flow).

If you really need a one-line solution just replace each newline with a semi-colon.
This User Gave Thanks to methyl For This Post:
# 6  
Old 01-21-2011
Mac 10.6.6

(This is just hobby/personal use. I'm on a mac (10.6.6). I have been strictly Windows since 3.1 and I'm trying to get more familiar with what my mac is able to do. I know i'm able to open the terminal app and interface using unix commands, but I don't really know unix at all. I know there's tons of apps for macs to do simple things but are just wasting space and processing so I figured, I might as well learn the OS because that should cover about 90% of those apps. I don't prefer wasting system resources either, so I want to get optimal use out of my system. I really dig apps that use the system properly, and cleverly, rather than rewriting functions to do what's already available thru calling system commands.)

methyl: thanks for the reply. I was playing around with shell scripting trying to figure it out. I was under the impression that I could call unix commands like I would call functions in a oop language, then pipe commands together to get like a variable out of the output, then feed that into some other unix command. Am I looking at this the wrong way?

i.e. in the shell:

command (feed result to) search_for_result_from_previous_command (feed result to) echo_to_standard_output

You can do this sort of thing with unix, right? Because I can imagine endless possibilities with a system like this.
# 7  
Old 01-21-2011
In future posts please mention that you are on a MAC and the version of MACOS. If not you may get solutions which do not run on your computer.


Quote:
command (feed result to) search_for_result_from_previous_command (feed result to) echo_to_standard_output
The MSDOS pipeline is pretty much the same as the unix pipeline from which it was derived (Imho to avoid M$ wrath).

Code:
dir | find /i "my_filename" | more

ls | grep -i "my_filename" | more

This User Gave Thanks to methyl For This Post:
 
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Solaris

Difference between commands

i need to know the difference between two commands ps -ef|grep oracle ps -ef|grep -v grep |grep oracle (1 Reply)
Discussion started by: smazshah
1 Replies

2. Shell Programming and Scripting

Difference between these cron commands

Hi all I want to make sure I was understanding this correctly if a cron job command was * */20 * * * command does that mean this command will run every 20 hours? also what is the difference between the following two? 0,20,40 * * * * command 20 * * * * command I believe the first... (3 Replies)
Discussion started by: subway69
3 Replies

3. AIX

HACMP: difference between 'cl' commands and 'cli' commands

Hi all, I'm new in this forum. I'm looking for the difference between the HACMP commands with the prefix "cl" and "cli". The first type are under /usr/es/sbin/cluster/sbin directory and the second are under /usr/es/sbin/cluster/cspoc directory. I know that the first are called HACMP for AIX... (0 Replies)
Discussion started by: peppix
0 Replies

4. Solaris

Performance difference between commands

Looking at the performance hit on my server, does it matter wich command I run? client # rsh server tar –cf - . | tar –cv –f – or server # tar –cf – . | rsh client ‘cd target && tar –xv -f –‘ I think it doesn't really matter because both command strings involve a tar being run on... (4 Replies)
Discussion started by: petervg
4 Replies

5. Shell Programming and Scripting

Difference between 2 grep - commands

Hi, I need to know the difference between this commands: grep * *search* grep "*" *search* As far as i know does the 2nd command search for files which have a name with *search* and greps then all which have chars from a-z in the file content. But was does the first command?? Best... (1 Reply)
Discussion started by: xus
1 Replies

6. Shell Programming and Scripting

Difference between the commands

HI all, Please clarify the difference between the following pm2srv:/var/opt/temip/vf/scripts/saiki#awk '{RS = ":"} ; {print $0}' testf2 hey:wasup:howru: Yes I am fine pm2srv:/var/opt/temip/vf/scripts/saiki#awk 'BEGIN { RS = ":" } ; { print $0 }' testf2 hey wasup howru Yes I... (0 Replies)
Discussion started by: saiki
0 Replies

7. Shell Programming and Scripting

Difference in auth key commands?

Good morning! What is the difference between: ssh-keygen -t rsa and ssh-keygen -b 2048 -t rsa? Thanks Bigben (2 Replies)
Discussion started by: bigben1220
2 Replies

8. UNIX for Dummies Questions & Answers

Difference in commands

Hello All, I have a question about the difference between two commands. I am using Korn and was told by the Unix admin that 'nohup <command> &' equals 'nohup ./<command> &. That there is no difference betwewen the two. Is this true? Also, does the command './<command> &' provide a disconnect... (4 Replies)
Discussion started by: grin1dan
4 Replies

9. Solaris

difference between these commands??

Hi, I would like to know what is the difference between executing the mount command in the following ways... eg: /usr/sbin/mount -F <something> AND mount -F <something> I mean , just executing the mount command as opposed to specifying the path and then executing it? ... (3 Replies)
Discussion started by: wrapster
3 Replies

10. UNIX for Dummies Questions & Answers

what's the difference of these two commands?

shouldn't they give the same output? echo `echo \`date\`` is the same as the command date echo `echo date` prints the word date thanks! (3 Replies)
Discussion started by: kfad
3 Replies
Login or Register to Ask a Question