2 added 203 characters in body
source | link

A possible solution in awk :

echo 'foo bar' | awk '{x=substr($1,1,1); y=substr($2,1,1); sub(x, y, $1); sub(y, x, $2); print $0}'
boo far

The two substr function calls will extract the first character from each of the records and the two calls to sub function will substitute the first appearance of those characters with each other.

A possible solution in awk :

echo 'foo bar' | awk '{x=substr($1,1,1); y=substr($2,1,1); sub(x, y, $1); sub(y, x, $2); print $0}'
boo far

A possible solution in awk :

echo 'foo bar' | awk '{x=substr($1,1,1); y=substr($2,1,1); sub(x, y, $1); sub(y, x, $2); print $0}'
boo far

The two substr function calls will extract the first character from each of the records and the two calls to sub function will substitute the first appearance of those characters with each other.

1
source | link

A possible solution in awk :

echo 'foo bar' | awk '{x=substr($1,1,1); y=substr($2,1,1); sub(x, y, $1); sub(y, x, $2); print $0}'
boo far