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
  • 6,615
  • 11
  • 53
  • 92

1 Answers1

0

You can use:

find . -name "*.go" -exec bash -c \
'cat header.txt "$1" > "$1".tmp && mv "$1".tmp "$1"' - {} \;
anubhava
  • 713,503
  • 59
  • 514
  • 593