Pass ls command output to diff


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Pass ls command output to diff
# 1  
Old 11-13-2015
Pass ls command output to diff

Hi ,

Can some one help me how to pass ls command output to diff command

ex : - ls *.xml will return files which have time stamps

Code:
         abc-<time-stamp>.xml
        xyz-<time-stamp>.xml

           diff   abc-<time-stamp>.xml  xyz-<time-stamp>.xml >> newfile.txt

we need to check this some 30 directories , so we need cd to directory and do ls and then pass file names from ls to diff

---------- Post updated at 07:04 AM ---------- Previous update was at 06:30 AM ----------

Can some one respond quickly

Last edited by Don Cragun; 11-13-2015 at 05:10 PM.. Reason: Add CODE and ICODE tags.
# 2  
Old 11-13-2015
Using terms like "urgent" or "quickly" and/or bumping up posts is not THAT well received in these fora as people are volunteers spending their free time trying to help people solve their problems.

You can help speed up things from your side by giving an excellent specification or description of the problem, respectively, including details of your system and using code tags as required by forum rules.

Assuming you are using a modern bourne type shell, you can use "command substitution" to supply a command's output to e.g. diff. To give a more taylored answer, more info is needed, like
- how many files are in each of those directories?
- check every files against each of the other files?
- all results to the same newfile?
- any dirs in that path to be excluded?
These 2 Users Gave Thanks to RudiC For This Post:
# 3  
Old 11-13-2015
Do you want files that have same name - time-stamp is the same value on both files?
Otherwise you need to be more exact in your requirement - by that I mean: please explain what you are doing -NOT how you think it should be done

If you do differences on every file from each of 30 directories, you will have a mountain of output to deal with. After a long wait. That would be true even if you had only 3 files in each directory.
# 4  
Old 11-13-2015
@ Rudic

- how many files are in each of those directories?
we will have many other files , we need to diff with the first file that was created in each directory of that day and with latest last file at the time of doing diff
- check every files against each of the other files?
No , need to diff from first file that was created in each directory of that day and with latest last file at the time of doing diff
- all results to the same newfile?
yes all results will be same file

we can put come thing echo "========= dir1 ============" in between
- any dirs in that path to be excluded?
no all dirs need to be checked




@ Jim

we need to diff with the first file that was created in each directory of that day and with latest last file at the time of doing diff and output should go single file
# 5  
Old 11-13-2015
So - where lies your problem? Using ls (together with other commands) to gain the two desired filenames, or presenting them to diff?
And, what you specify in post#4 will need a script, more or less, which goes beyond what you said in post#1 and the title. Why don't you start over and give us a detailed spec accompanied with meaningful input and desired output samples? We still don't know your OS nor shell version...
# 6  
Old 11-13-2015
yeah we need script
detailed spec would be like

i need to cd to 30 to 40 dirs and need to ls for ls *.xml and we need to diff the first file that was created in each directory of that day and with latest last file at the time of doing diff
im looking how we can present the desired files to diff , i hope specification clear

its Redhat 6 OS being used

# 7  
Old 11-13-2015
Is this a homework assignment? Homework assignments must be filed in the Homework & Coursework Questions forum and must include a fully filled out homework template from the Rules for Homework & Coursework Questions forum.

What shell are you using?

Why are you restricting our options by just using ls to get a list of file when find would simplify this task?
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

How to read the output of a command line by line and pass it as a variable?

Hi, I have some 2000 names in a table like below. Java Oracle/SQL ANSI SQL SQL,DWH,DB DB&Java And by using for loop in my code i am able to get a single word but if there is any special character or space then it is considering as a next line. I have to execute the below queries in... (10 Replies)
Discussion started by: Samah
10 Replies

2. Shell Programming and Scripting

Help with diff output

I am running diff between two directories dir1 and dir2. diff --exclude --recursive --brief -b dir1 dir2 The output of the above command is Files dir1/java/abc/bcd/abc9991.java and dir2/java/abc/bcd/abc9991.java differ Files dir1/java/abc/bcd/abc9933.java and... (11 Replies)
Discussion started by: gaurav99
11 Replies

3. UNIX for Dummies Questions & Answers

What does this diff output mean?

35d34 < What does that mean in diff? (3 Replies)
Discussion started by: glev2005
3 Replies

4. Shell Programming and Scripting

diff output next to each other

I have two files to compare, but diff output doesn't give me decent output I want. The portion of the two files are shown below. file 1) Authorize <1> Transaction Database Slave 3 <1> CPM HTTP Proxy Server <1> SSP (TDB Server) <1> CPM Application Authorization <7> CPM Script... (5 Replies)
Discussion started by: Daniel Gate
5 Replies

5. Shell Programming and Scripting

Process diff command output in a shell script

diff -yta file1 file2 #!/usr/abc/b/bin/perl5.6 | #!/usr/abc/b/bin/perl5.8 Notable thing about above line is "|" appears at 62nd position. When the same line is assigned in a variable in a ksh script, using ss=$(diff -yta file1 file2) it appears as ... (4 Replies)
Discussion started by: bhaliyajalpesh
4 Replies

6. Shell Programming and Scripting

[csh] How to capture output from a command and pass it on to a variable?

Hi there! I'm trying to write a script that will capture output from a command and assign it to a variable. Let's say, for example, I'd like to catch from inside the script whatever the following command outputs: ls *.aaa and put it into a variable "listoffiles". What I tried was: set... (3 Replies)
Discussion started by: machinogodzilla
3 Replies

7. Shell Programming and Scripting

parsing output from a diff command...

hi, i have a script which pipes the output of a diff -rq command into a separate file/ it would read something like this: Files mod1/lala/xml/test1.txt and mod2/lala/xml/test1.txt differ Only in mod2/lala/xml: test2.txt What i need to do is to parse this file so i end up with just a... (5 Replies)
Discussion started by: kam
5 Replies

8. UNIX for Dummies Questions & Answers

diff output

I have two CSV files and I would like to create a third CSV file containing the differences between the two. I understand the diff command can be used to list differences between two files. My problem is that when I pipe the output into a third CSV file, the line numbers and other formatting... (3 Replies)
Discussion started by: paulp
3 Replies

9. Shell Programming and Scripting

reformat the output from "diff" command

Hi all, I use the diff command and got the output: $> diff -e file1.txt file2.txt 15a 000675695 Yi Chen Chen 200520 EASY 50 2/28/05 0:00 SCAD Debit Card Charge . 12a 000731176 Sarah Anderson 200520 EASY 25 2/28/05 0:00 SCAD Debit Card Charge . 11a... (5 Replies)
Discussion started by: CamTu
5 Replies

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