Trim leading and trailing spaces from a string in awk
If you want to trim all spaces, only in lines that have a comma, and use awk, then the following will work for you: awk -F, ‘/,/{gsub(/ /, “”, $0); print} ‘ input.txt If you only want to remove spaces in the second column, change the expression to awk -F, ‘/,/{gsub(/ /, “”, $2); print$1″,”$2} … Read more