I need some help with adding lines to file and substitute a pattern.
Ok I have a file:
#cat names.txt
name: John Doe
stationed: 1
name: Michael Sweets
stationed: 41
.
.
.
And would like to change it to:
name: John Doe
employed
permanently
stationed: 1-office
name: Michael Sweets
employed
permanently
stationed: 41-office
Lines "employed" and "permanently" are static and I would like to add those two lines after every name. Then I would like to add a suffix "-office" after every number.
Can anyone please give me a solution.
thanks in advance.
local $/="\n\n";
while(<DATA>){
s/(name\s*:\s*[^\n]*)\n(.*)/$1."\nemployed\npermanantly\n".$2."-office"/e;
print;
}
__DATA__
name: John Doe
stationed: 1
name: Michael Sweets
stationed: 41