I try to create a script for a template. In this, I want to replace Strings on a static position. But after the first sed try, the default String is corrupted.
my script:
#!/bin/sh
# default record
record="NNNNNNNNNNNNNNNNNNNN CCCCCCCCCCCCCCCCCCCC BBBBBBBBBB 001"
echo "$record"
# read values from configuration file
VAR1="User Name: Sibob" # 20
VAR2=" Berlin" # 20
VAR3="1983 [US]" # 10
record=`echo $record | sed -e "s/\(.\{0\}\)\(.\{20\}\)/\1$VAR1/" `
echo "$record"
record=`echo $record | sed -e "s/\(.\{21\}\)\(.\{20\}\)/\1$VAR2/" `
echo "$record"
record=`echo $record | sed -e "s/\(.\{54\}\)\(.\{10\}\)/\1$VAR3/" `
echo "$record"
the result of the script is:
$ ./rename.sh
NNNNNNNNNNNNNNNNNNNN CCCCCCCCCCCCCCCCCCCC BBBBBBBBBB 001
User Name: Sibob CCCCCCCCCCCCCCCCCCCC BBBBBBBBBB 001
User Name: Sibob CCCC BerlinBBBBBBB 001
User Name: Sibob CCCC BerlinBBBBBBB 001
User Name: Sibob CCCC BerlinBBBBBBB 001
But what I want is:
User Name: Sibob Berlin 1983 [US] 001
The problem is, that the blanks will be removed. In this case the replacement of the strings doesn't work correctly.
Have anyone an idea?