0

So, my program:

#!/bin/bash

OIFS="$IFS"
IFS=$'\n'

find teste1 -type f | while read -r firstResult

do

  find teste2 -type f | while read -r secondResult

   do

    firstName=${firstResult##*[/|\\]}
    secondName=${secondResult##*[/|\\]}

     if [[ "$( echo "$firstName" | tr [A-Z] [a-z])" == "$( echo "$secondName" | tr [A-Z] [a-z])" ]]; then
      echo "$firstResult" "$secondResult" >> equal.lst
     else
      echo "$firstResult" "$secondResult" >> notEqual.lst
     fi

      if [[ $firstName == $secondName ]]; then
       echo "$firstResult" "$secondResult" >> equal2.lst
      fi

   done

done

diff -2 equal.lst equal2.lst >> renamedFiles.lst

I am having some difficulty on the 'diff' part, as the output on the 'renamedFiles.lst' shows something like:

3d2 < teste1\TESTE.pub teste2\TEstE.pub

8d6 < teste1\TeStE2.xlsx teste2\testE2.xlsx

So my question is: How can I remove the "3d2" and "8d6" part? Is there a way for me to do so? I wanted to create a report for the differences and it would be "cleaner" if it didn't have those numbers. I know why the numbers are there but is there a way to remove it?

1 Answer 1

1

Use the line formats to specify the exact format desired. For example:

diff -2 "--old-line-format=<%L" "--new-line-format=>%L" "--unchanged-line-format=" equal.lst equal2.lst

Results in bare output like:

>new line
<old line
Sign up to request clarification or add additional context in comments.

4 Comments

Hmm, I tried your way, and read about line-format at Diff Man Page but anytime I actually try something with line-format, it just outputs what would output if it didn't have "-2". What I mean is that it is outputting a lot more than I wanted. It isn't outputting the diff from the 1st file to the 2nd file, it's outputting the diff from both of them into "renamedFiles"
I'm doing this on Linux here, so I don't know all the differences. Does your diff usag message say it supports the line formats?
What exactly do you mean by that? Sorry, I'm completely new to this. Plus, I am using Windows :) Dunno if that makes a difference to you :P
Hey! I solved it. Read your code again and I noticed what I was doing wrong. Thanks a bunch for your help!

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.