Matt
Matt

Reputation: 1032

diff command with regex (bash)

I want to see if 2 files are different. If they are I want to output something. If not, output something else. This is the code I use and it works fine

if diff file1.txt file2.txt >/dev/null ; then
  echo "Not different"
else
  echo "Files are different"
fi

However, now I want to add conditions to my diff such as:

| grep "<" | awk '{$1=""; print $0}' | sed '/#/d'

How do i add this regex in my diff command so that my if statements will work??

Thank you

Upvotes: 0

Views: 206

Answers (1)

Stefan M
Stefan M

Reputation: 889

Test the result of your operation.

r=$(diff file1.txt file2.txt | grep "<" | awk '{$1=""; print $0}' | sed '/#/d')
if [ -z "${r}" ] ; then

Edit: You were checking for output, not for error code.

Upvotes: 1

Related Questions