Find the answer to your Linux question:
Results 1 to 5 of 5
hi everyone, i want to compare two lists of files. i want to check which file in List A is not in list B.this is how the lists are; List ...
  1. #1
    Just Joined!
    Join Date
    Dec 2008
    Posts
    19

    compare numbers within a string

    hi everyone,
    i want to compare two lists of files. i want to check which file in List A is not in list B.this is how the lists are;
    List A List B
    file21.txt file21.txt
    file23.txt file 22.txt
    file24.txt file23.txt
    file25.txt file24.txt

    so i want the program to tell me that file22.txt is missing from list A.
    does anybody have idea on how i can program this? help please.
    thank u.

  2. #2
    Linux Engineer wje_lf's Avatar
    Join Date
    Sep 2007
    Location
    Mariposa
    Posts
    1,192
    No need to program anything. Do this at the command line:
    Code:
    man diff
    and all will be revealed.
    --
    Bill

    Old age and treachery will overcome youth and skill.

  3. #3
    Just Joined!
    Join Date
    Dec 2008
    Posts
    19
    thank you for your prompt reply.

  4. #4
    Just Joined!
    Join Date
    Dec 2008
    Posts
    19

    About diff and grep command.

    About diff and grep command. I am now trying to write a script to compare two files by using diff command and i grep the changes in each line and then count the those lines.
    I use this command
    diff fileA fileB | grep -e '^c[1-9]' | wc -l

    the problem is when there is consecutive changes in two files the output is combined as
    $diff fileA fileB | grep -e '^c[1-9]'
    c3 10
    and hence i get when i count the lines it gives 1
    $diff fileA fileB | grep -e '^c[1-9]' | wc -l
    1
    i would like to count the ocurrence of the changes.In this case i expect the grep output to be
    c3
    c4
    c5 etc.
    and when i count them lines i want to have
    $diff fileA fileB | grep -e '^c[1-9]' | wc -l
    8

    please help!

  5. #5
    Linux Engineer wje_lf's Avatar
    Join Date
    Sep 2007
    Location
    Mariposa
    Posts
    1,192
    How about this?
    Code:
    #!/bin/bash
    
    cat > 4a.txt <<EOD
    aaa
    bbb
    ccc
    ddd
    eee
    EOD
    
    cat > 4b.txt <<EOD
    aaa
    bbb
    eee
    fff
    ggg
    hhh
    EOD
    
    diff 4a.txt 4b.txt | grep '^[<>]' | wc -l
    --
    Bill

    Old age and treachery will overcome youth and skill.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
...