-1

File1:

Data will be inserted on Thursday  
Messages has been sent at 6pm  
Office hours is from 9am to 6pm  
All the employees are present  

Output what I want:

DMS Data will be inserted on Thursday  
DMS Messages has been sent at 6pm  
DMS Office hours is from 9am to 6pm  
DMS All the employees are present  

-or-

Output what I want:

Data will be inserted on Thursday DMS
Messages has been sent at 6pm DMS
Office hours is from 9am to 6pm DMS
All the employees are present DMS

I want to add the word DMS in every lines of my file. It may be added at the first or at the end of the line.

slm
  • 363,520
  • 117
  • 767
  • 871
Nainita
  • 2,712
  • 12
  • 33
  • 50

1 Answers1

0

Try this, it will help you. Open the file in vi editor:

$ vi /file/location  

:1,100 s/^/DMS/ --> Enter  
  • 1,100 is exactly from which line you want to start and end.
  • s is the substitution command and ^ means the the line starting.

Or you can do it without opening the file, using GNU sed:

sed -i 's/^/DMS /' /your/file/location
cuonglm
  • 150,973
  • 38
  • 327
  • 406
AReddy
  • 3,122
  • 5
  • 35
  • 75
  • I don't think you *can* do it without opening the file - at least not without directly editing the underlying block device, and probably the filesystem will object to that, anyway - and I'm pretty positive you definitely can't w/ `sed`by asking it to open the file. – mikeserv Aug 02 '15 at 11:07
  • I was not able to modify my question as I was facing some technical problem. The question has been marked as duplicate. But today I have again edited my question. But if I want to add the word at the last of my line, then what could be the solution. @cuonglm Your solution has helped me. – Nainita Aug 03 '15 at 09:31
  • @Nainita: You should raise a new question. – cuonglm Aug 03 '15 at 09:33