Find the answer to your Linux question:
Results 1 to 2 of 2
I have developed a shell script which will scan two files and then put the similar records in a third file.The script is follows rm $filename3 touch $filename3 exec < ...
  1. #1
    Just Joined!
    Join Date
    Jun 2007
    Posts
    3

    Exclamation script for scanning two files

    I have developed a shell script which will scan two files and then put the similar records in a third file.The script is follows


    rm $filename3
    touch $filename3

    exec < $filename1

    while read line
    do
    exec <filename2
    while read line1
    do
    if [ $line -eq $line1 ]
    echo $line >> filename3
    end if
    done
    done

    But the above shell script is not working.
    Could anyone help me out?

  2. #2
    Trusted Penguin Cabhan's Avatar
    Join Date
    Jan 2005
    Location
    Seattle, WA, USA
    Posts
    3,230
    You use 'fi' to end an if block, not 'end if'.

    Also note that you are going to read the first line of file1, and then all of file2 and print out all matching lines. Then you're going to read the second line of file1 and all of file2 and print all matching lines. You want to read through both files together.
    DISTRO=Arch
    Registered Linux User #388732

Posting Permissions

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