foo bar foobarHow can I delete all leading and/or trailing blank spaces, tab from each line using sed command?
Tutorial details | |
---|---|
Difficulty | Easy (rss) |
Root privileges | No |
Requirements | sed/awk/perl |
Estimated completion time | 2 minutes |
- Perl.
- Python.
- Awk and friends.
Perl example
The syntax is:perl -lape 's/\s+//sg' input > output
Sample outputs:foo bar foobarOr use -pie syntax to update file:
cat input
perl -lapi -e 's/\s+|^\n//sg' input
cat input
See perl man page for more information.Sed example
The syntax is:sed -e 's/^[ \t]*//' -e 's/[ \t]*$//' input > outputOR updated file in a single go with the -i option:
sed -i -e 's/^[ \t]*//' -e 's/[ \t]*$//' inputSee sed command man page for more information.
Awk example
The syntax isawk '{$1=$1}{ print }' input > outputYou can also use gsub() substring matching the regular expression function. See awk man page for more information.
http://www.cyberciti.biz/faq/sed-tip-delete-all-blank-white-spaces/
No hay comentarios:
Publicar un comentario