0

File1:

Dms 01.01.2015 feeder1 6kv close at 04:30  
Updated  
Dms 01.01.2015 feeder1 6kv open at 06:20  
Updated  
Dms 04.02.2015 feeder10 6kv close at 17:23  
Updated  
Dms 04.02.2015 feeder12 6kv open at 23:30  
Updated  
Dms 12.04.2015 feeder4 6kv disturb at 12:30  
Updated  
Dms 12.04.2015 feeder7 6kv close at 11:09  
Updated  
Dms 16.05.2015 feeder8 6kv open at 13:10  
Updated  
Dms 01.06.2015 feeder3 6kv close at 05:07  
Updated

Output will be:

Dms 01.01.2015 feeder1 6kv close at 04:30  
Updated  
Dms 01.01.2015 feeder1 6kv open at 06:20  
Updated  
Dms 04.02.2015 feeder10 6kv close at 17:23  
Updated  
Dms 04.02.2015 feeder12 6kv open at 23:30  
Updated  
Dms 12.04.2015 feeder4 6kv disturb at 12:30  
Updated  
Dms 12.04.2015 feeder7 6kv close at 11:09  
Updated  
Dms 16.05.2015 feeder8 6kv open at 13:10  
Updated  
Dms 01.06.2015 feeder3 6kv close at 05:07  
EOF

I want to change only the last Updated to EOF using command.

Please be noted, my line numbers in file is not fixed. It may be 100 lines or may be 500 lines but I want to change only the last word using command.

6

With sed:

sed -e '$s/Updated/EOF/' file
  • $ means it will update only the last? @cuonglm – pmaipmui Jun 15 '15 at 15:36
  • 2
    @Nainita: $ in address match only the last line. – cuonglm Jun 15 '15 at 15:38
2

Using Perl:

< inputfile perl -0777 -pe 's/Updated$/EOF/'

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.