User Tools

Site Tools


bash:files:delete_leading_and_trailing_whitespace_from_each_line_in_a_file

BASH - Files - Delete leading and trailing whitespace from each line in a file

Delete leading and trailing whitespace from each line.


Using awk

awk '{gsub(/^[ \t]+|[ \t]+$/,"");print}' filename

Using sed

sed '/^[[:space:]]*$/d' input.file
sed -i '/^[[:space:]]*$/d' input.file
sed -r '/^\s*$/d' input.file > output.file
sed -i '/^[[:space:]]*$/d' /tmp/data.txt

bash/files/delete_leading_and_trailing_whitespace_from_each_line_in_a_file.txt · Last modified: 2022/06/13 10:35 by peter

Donate Powered by PHP Valid HTML5 Valid CSS Driven by DokuWiki