Often you may want to use Bash to reverse the words in each line of a file.
You can use awk with the following syntax to do so:
awk '{for(i=NF;i>=1;i--) printf "%s ", $i;print ""}' teams.txt
This particular example will reverse the words in each line of the file named teams.txt.
The following example shows how to use this syntax in practice.
Example: Use Bash to Reverse the Words in Each Line of a File
Suppose that we have a file named teams.txt that contains the names of various basketball teams.
We can use the cat command to view the contents of this file:

Now suppose that we would like to reverse the words in each line of the file.
We can use the following syntax to do so:
awk '{for(i=NF;i>=1;i--) printf "%s ", $i;print ""}' teams.txt
The following screenshot shows how to use this syntax in practice:

Notice that the words are now reversed in each line of the file.
Also note that you could use the > command to save these results to a new file:
awk '{for(i=NF;i>=1;i--) printf "%s ", $i;print ""}' teams.txt > new.txt
This syntax would reverse the words in each line of the file named teams.txt and save the results to a new file named new.txt.
Feel free to use similar syntax to reverse the words in each line of your own file.
Related Tutorials
The following tutorials explain how to perform other common tasks in Bash:
Bash: How to Extract Text Between Two Strings
Bash: How to Replace Multiple Characters in String
Bash: How to Replace All Occurrences of String in File
