Add a word in front or at the end of each line

Lets say that you have a file with 1000 lines and you want to add the word start in front of each line and the word end in the end of each line. What can you do?
Let’s assume that the file is named magic.txt the command will be:
sed ‘s/^/start/g;s/$/end/g’ magic.txt

So if you want to add only in front of file use:
sed ‘s/^/start/g’ magic.txt

and if you want to add a word only at the end of the file:
sed ‘s/$/end/g’ magic.txt

Isn’t it simple?

Αφήστε μια απάντηση

Η ηλ. διεύθυνσή σας δεν δημοσιεύεται. Τα υποχρεωτικά πεδία σημειώνονται με *