How to remove leading and trailing whitespaces?
问题 I'm using awk '{gsub(/^[ \t]+|[ \t]+$/,""); print;}' in.txt > out.txt to remove both leading and trailing whitespaces. The problem is the output file actually has trailing whitespaces! All lines are of the same length - they are right padded with spaces. What am I missing? UPDATE 1 The problem is probably due to the the fact that the trailing spaces are nor "normal" spaces but \x20 characters (DC4). UPDATE 2 I used gsub (/'[[:cntrl:]]|[[:space:]]|\x20/,"") an it worked. Two strange things: