Remove empty lines from txtfiles, remove spaces from start and end of line
问题 Which one would be better: sed -e '/^$/d' *.txt sed 'g/^$/d' -i *.txt Also, how do I remove spaces from beginning and end of each line in the text file? 回答1: $ sed 's/^ *//; s/ *$//; /^$/d' file.txt `s/^ *//` => left trim `s/ *$//` => right trim `/^$/d` => remove empty line 回答2: Even more simple method using awk. cat filename.txt | awk 'NF' | awk '{$1=$1;print}' awk 'NF' - This will remove all blank/empty lines. awk '{$1=$1;print}' - This will remove only trailing white spaces, (both left and