nixCraft Linux / UNIX Newsletter

Link to nixCraft: Linux Tips, Hacks, Tutorials, And Ideas In Blog Format (RSS/FEED)

How to trim leading and trailing white space in bash

Posted: 12 Mar 2022 06:31 AM PST

See all GNU/Linux related FAQ

So I have this specific use case where I get data in a comma-separated values (CSV) file. I pick up the company name, address, telephone, email, and some other data from that file. Once data is collected, I create a final pdf using a simple script. Unfortunately, data comes with unwanted leading and trailing white spaces in each field. So my final pdf file gets messed up because of those white space. Let us see how to trim leading and trailing white space for a string in Bash running on Linux or Unix machines.

Love this? sudo share_on: Twitter - Facebook - LinkedIn - Whatsapp - Reddit

The post How to trim leading and trailing white space in bash appeared first on nixCraft.