1

I guess this is a simple question but I seem to be able to understand why this is incorrect.

#!/bin/sh
header=`cat header.txt`
find . -name "*.go" -exec sed -i "" -e "1s|^|$header|" {} \;

This piece of script should add the content of header.txt to all .go files. But instead it outputs: sed: 1: "./restapi/operations/su ...": invalid command code .

I have found this answer, but the issue is still there.

Community
  • 1
  • 1
Bob van Luijt
  • 7,153
  • 12
  • 58
  • 101

1 Answers1

0

You can use:

find . -name "*.go" -exec bash -c \
'cat header.txt "$1" > "$1".tmp && mv "$1".tmp "$1"' - {} \;
anubhava
  • 761,203
  • 64
  • 569
  • 643