0

I need to make a copy of a large code and replace just a name in the code. I have to do this multiple times with a list of names.

eg:

I have the names:

Jay
Joy
Jane
Juda

and I have an example code/text:

print("Hi");
Print("Hello")
print("Jay"); # here

I want the output to be like:

print("Hi");
Print("Hello")
print("Jay"); # here

print("Hi");
Print("Hello")
print("Joy"); # here

print("Hi");
Print("Hello")
print("Jane"); # here

ie, just changing one part of the code but have to repeat all the other steps.

Ted Lyngmo
  • 93,841
  • 5
  • 60
  • 108
Abhi Raj
  • 11
  • 3

1 Answers1

0
awk '{printf("print(\"Hi\");\nprint(\"Hello\");\nprint(\"%s\"); # here\n\n",$0)}' input_file.txt

UPDATE: as I understand your comment, you need a template

template-file:
bla
bla bla
bla %NAME% bla
bla

script:
IFS=$'\n'
for i in `cat names`; do
sed "s/%NAME%/$i/" template-file
done
gabor.zed
  • 134
  • 1
  • 2
  • 6