oldjamey
6/19/2013 - 6:12 AM

remove extra whitespaces

remove extra whitespaces

#!/bin/bash

# removes all "extra" whitespace (leaves normal spaces)
cat "web.txt" | awk '{$1=$1}1'

# removes only leading and trailing whitespace
cat "web.txt" | awk '{gsub(/^ +|  +$/,"")}1'

# this perl command should do the same thing
cat "web.txt" | perl -lape 's/^\s+|\s+$//g'