Friday, December 12, 2014

Ways to Replace Multiple Spaces in Text (Awk,Sed,tr)

The awk way:  
$ cat file.txt | awk '{gsub("[ ]+"," ");print}' 
The tr way:
$ cat file.txt | tr -s " " 
where -s stands for squeeze and can be used on any character not only spaces
The sed way: 
$ cat file | sed -r 's/[ ]+/ /g'

No comments:

Post a Comment