Skip to main content
added 209 characters in body
Source Link
Rakesh Sharma
  • 1.1k
  • 1
  • 6
  • 3

Using GNU sed we can clip any spaces sticking around a tabb as shown

$ sed -Ei -e 's/[ ]*\t[ ]*/\t/g' file

With awk we iterate over the fields and then trim the field:

$ awk -F '\t' -v OFS='\t' '
{
  for (i=1; i<=NF; ++i) {
    gsub(/^[ ]+|[ ]+$/, "", $i)
  }
}1
' file > foo && mv foo file 

Using GNU sed we can clip any spaces sticking around a tabb as shown

$ sed -Ei -e 's/[ ]*\t[ ]*/\t/g' file

Using GNU sed we can clip any spaces sticking around a tabb as shown

$ sed -Ei -e 's/[ ]*\t[ ]*/\t/g' file

With awk we iterate over the fields and then trim the field:

$ awk -F '\t' -v OFS='\t' '
{
  for (i=1; i<=NF; ++i) {
    gsub(/^[ ]+|[ ]+$/, "", $i)
  }
}1
' file > foo && mv foo file 
Source Link
Rakesh Sharma
  • 1.1k
  • 1
  • 6
  • 3

Using GNU sed we can clip any spaces sticking around a tabb as shown

$ sed -Ei -e 's/[ ]*\t[ ]*/\t/g' file