LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - General (https://www.linuxquestions.org/questions/linux-general-1/)
-   -   add word to each line of the file? (https://www.linuxquestions.org/questions/linux-general-1/add-word-to-each-line-of-the-file-316708/)

ziggie216 04-24-2005 01:41 PM

add word to each line of the file?
 
If I want to insert a word into the beginning of each line in a file do I use the command "paste"?

from

is a test
is a test2
is a test3


to

this is a test
this is a test2
this is a test3

if so whats the format?

bulliver 04-24-2005 02:07 PM

I would use sed instead...
Code:

$ cat file
is a test
is a test2
is a test3
$ cat file | sed -e 's/is/this is/g' >> file2
$ cat file2
this is a test
this is a test2
this is a test3

Paste will combine the lines of two files, separated by a tab.

makuyl 04-24-2005 02:45 PM

Or for the same file "sed -i -e 's/is/this is/' filename"
The "g" would add "this" to all words "is" in a line.

bulliver 04-24-2005 07:51 PM

Your right makuyl, good catch...

slackie1000 04-25-2005 04:19 AM

hi there,

just to contribute:
if your line does not share the same pattern you can use ^
Code:

sed "s/^/this /g" your_file
regards

slackie1000


All times are GMT -5. The time now is 04:13 AM.