Add a space or tab before the last character in each line

awksedtext processing

I have a file with a list of values that end with a letter. Is there an easy way to add a space or tab before the last character of each line to separate the number from the letter?

44A  
354T  
1453C  
77D

So that the output looks like this:

44 A  
354 T  
1453 C  
77 D

Best Answer

If you never have any white space after the last character and before the end of the line, use:

sed 's/.$/ &/' file

or

perl -pe 's/.$/ $&/' file

If you can have whitespace before the end of the line, use this instead:

perl -pe 's/(.*)(\S)/$1 $2/' file
Related Question