0

I'm new to Unix and shell scripting, I'm able to run a code from terminal but the same command giving error when run in a shell script.

#!/bin/bash
diff <((sort doc1) <(sort doc2)) | grep -x '.\{6\}' >sample.txt

I'm getting this error when I run the shell:

/App$ sh filediff.sh 
filediff.sh: 4: filediff.sh: Syntax error: "(" unexpected
  • The double brackets in diff <((sort doc1) <(sort doc2)) don't look reasonable. – Tomasz Dec 21 '16 at 6:48
4

When you run your diff command in normal shell, you are using the current shell (mostly bash).

You indent to use a bash shell for your script, but if you call your script with "sh filediff.sh" you call a sh-Shell, which is a bit different from bash.

You can call your script with

bash filediff.sh

or you make it executable with

chmod +x filediff.sh

and call it with

./filediff.sh
-1

The diff command works for analyzing two files and prints the lines that are different. You are not providing proper input files to diff command:

Simple modified working script is:

sort doc1 | tee tempdoc1
sort doc2 | tee tempdoc2
diff tempdoc1 tempdoc2 | grep -x '.\{6\}'  > sample.txt
echo "Following is difference:"
cat sample.txt

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.