Often you may want to use Bash to add specific text to the beginning of each line in a file.
The easiest way to do so is by using awk with the following syntax:
awk '{ printf "team name: "; print }' teams.txt > teams_new.txt
This particular example will add the text “team name: ” to the beginning of each line in the file named teams.txt and save the results to a new file named teams_new.txt.
The following example shows how to use this syntax in practice.
Example: Add Text to Beginning of Each Line in File Using Bash
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:

Suppose that we would like to add the text “team name: ” to the beginning of each line in the file.
We can use the following syntax to do so:
awk '{ printf "team name: "; print }' teams.txt > teams_new.txt
The following screenshot shows how to use this syntax in practice:

Notice that when we use the cat command to view the new file named teams_new.txt we can see that it contains the same content as the original teams.txt file with the text “team name: ” added to the beginning of each line.
Feel free to use similar syntax to add specific text to the beginning of each line in your own file.
Related Tutorials
The following tutorials explain how to perform other common tasks in Bash:
Bash: How to Find Duplicate Lines in File
Bash: How to Delete All Empty Lines in File
Bash: How to Count Number of Unique Lines in File
