0
for i in $(find template -type f | sed 's/^template//') ; do
    diff -wBNu {,./template}$i

I can understand the for loop which will traverse all the files in the template directory and then replace all the sentence starting with template with ''. Is this understanding correct? What does the diff do here?

2

The braces perform shell 'brace expansion'. The construct {,./template}$i produces a pair of words, both containing the value of $i, but the latter has ./template prepended. Try the command

echo foo{,bar}

at the shell prompt to see it in action. This is documented under "Brace expansion" in the bash manual.

  • Thanks for the answer.But in the for loop does the sed command replace the filename, or the content of the file? – Nilesh Chaudhary Sep 22 '16 at 7:21
  • Sed command works on its input. In this case it is the output of the find command, which is a list of found files. – andrybak Sep 22 '16 at 7:52

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.