# Return to Answer

 2 added 203 characters in body edited Mar 22 '14 at 0:54 mkc 6,20844 gold badges3131 silver badges4646 bronze badges 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 answered Mar 22 '14 at 0:29 mkc 6,20844 gold badges3131 silver badges4646 bronze badges 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 ``````