Insert space between digit and alphabet on specific column Code Answer

Hello Developer, Hope you guys are doing great. Today at Tutorial Guruji Official website, we are sharing the answer of Insert space between digit and alphabet on specific column without wasting too much if your time.

The question is published on by Tutorial Guruji team.

How do I insert a space between column 5 digits and alphabets, the error code should be like that: 554 RTR:BL 421 MFF:MT

Timestamp:    EmailTo:          EmailFrom:         IPAddress:      ErrorCodes:
2016-06-19  saadiahk@aol.com Haroon@deignplus.cz  16.23.29.141     554RTR:BL
2016-06-20  saadiahk@aol.com Haroon@knsaifelt.com 13.43.219.141    421MFF:MT

Answer

Assuming there will be total of 3 digits on 5th column, using GNU sed you can do something like,

sed -r 's/([^s]*s){5}[0-9]{3}/& /' filename

Sample:

$ sed -r 's/([^s]*s){5}[0-9]{3}/& /' filename

Timestamp:    EmailTo:          EmailFrom:         IPAddress:      ErrorCodes:
2016-06-19  saadiahk@aol.com Haroon@deignplus.cz  16.23.29.141     554 RTR:BL
2016-06-20  saadiahk@aol.com Haroon@knsaifelt.com 13.43.219.141    421 MFF:MT

Explanation :

  • The first five fields are described by zero or more characters that are not a space separated [^s]* followed by space.

  • The error code is described by first 3 digits followed by alphabets. The replacement is everything that is matched & with a space added afterwards.

We are here to answer your question about Insert space between digit and alphabet on specific column - If you find the proper solution, please don't forgot to share this with your team members.

Related Posts

Tutorial Guruji