Given your sample input and your for loop, a trivial way to get what you want is:
sed -e 's/ *TRUE */ FALSE /' /tmp/test
Note that there are three tab characters before and after the FALSE in the above substitution.
Note also that there are no tab characters in your input and the number of spaces in your input don't match what would be produced if the tabs had been converted to spaces, but this gives what you said you want given what you said is in your input file.
If you have a file that has a list of values you want to match in field 1 of your input lines in /tmp/test (in a file named keys
in the following examples) one of the following examples may do what you want. They provide different ways of handling spacing around TRUE and FALSE, printing only matched lines or printing all lines, and changing or preserving existing spacing
#!/bin/ksh
echo "Use sed to change TRUE surrounded by spaces to 3 tabs FALSE 3 tabs"
sed -e 's/ *TRUE */ FALSE /' /tmp/test
echo
echo "Use awk to change TRUE to FALSE on lines matching given keys and
print changed lines. (Spaces and tabs are not changed.)"
awk 'FNR==NR{
m[$1]
next
}
substr($1, 1, index($1, ".") - 1) in m {
sub(/TRUE/, "FALSE")
print
}' keys /tmp/test
echo
echo "Use awk to change TRUE to FALSE on lines matching given keys and
print changed lines. (Each set of spaces and tabs is changed to 3 tabs.)"
awk 'FNR==NR{
m[$1]
next
}
substr($1, 1, index($1, ".") - 1) in m {
sub(/[ \t]*TRUE[ \t]*/, "\t\t\tFALSE\t\t\t")
print
}' keys /tmp/test
echo
echo "Use awk to change TRUE to FALSE on lines matching given keys and
print all lines. (Each set of spaces and tabs on lines that have been
changed is changed to 3 tabs.)"
awk 'FNR==NR{
m[$1]
next
}
substr($1, 1, index($1, ".") - 1) in m {
sub(/[ \t]*TRUE[ \t]*/, "\t\t\tFALSE\t\t\t")
}
{ print
}' keys /tmp/test
echo
echo "Use awk to change TRUE to FALSE on lines matching given keys and
print all lines. (Each set of paces and tabs is changed to 3 tabs.)"
awk 'FNR==NR{
m[$1]
next
}
{ if(substr($1, 1, index($1, ".") - 1) in m)
sub(/[ \t]*TRUE[ \t]*/, "\t\t\tFALSE\t\t\t")
else sub(/[ \t]*TRUE[ \t]*/, "\t\t\tTRUE\t\t\t")
print
}' keys /tmp/test
This was tested with the file keys
containing the following three lines:
TSCmerge77
TSCmerge100
TSCmerge101
I used ksh in my tests, but any shell that supports basic Bourne shell syntax should work fine. This was tested on OS X. If you're using a Solaris system, use nawk or /usr/xpg4/bin/awk instead of awk.