Forrest logo
back to the awk tool

awk:ai:b03c7

how can I use awk to replace all multiple spaces in text file with a single space
$ awk '{gsub(/ +/, " ")}1' ${filename}
try on your machine

This command uses awk to replace all occurrences of two or more spaces with a single space in the file.txt.

This explanation was created by an AI. In most cases those are correct. But please always be careful and never run a command you are not sure if it is safe.

Questions that are answered by this command:

  • how can I use awk to replace all multiple spaces in text file with a single space?
back to the awk tool