Ask Your Question

how to replace a line in the file without using any text editor?

asked 2014-10-25 15:41:57 -0600

Tiger gravatar image

updated 2014-10-26 05:39:04 -0600

FranciscoD_ gravatar image

suppose the content of a file is: tiger fedora ubuntu redhat

and i want to replace ubuntu -> basic

and the content of file make is tiger fedora basic redhat

edit retag flag offensive close merge delete



Not really a Fedora related question really - it's been asked thousands of times on the internet too :) Generally a good idea to first use Google and post only if you don't find the answer - it's good for you - it sharpens your Google-fu and you learn a lot more :D

FranciscoD_ gravatar imageFranciscoD_ ( 2014-10-26 05:35:16 -0600 )edit

1 Answer

Sort by ยป oldest newest most voted

answered 2014-10-25 16:34:52 -0600

vtrefny gravatar image

Easiest way is to use sed:

sed -i 's/ubuntu/basic/g' filename

This command will replace all "ubuntu" strings with "basic". If you want to replace only lines containg only the word "ubuntu", use

sed -i 's/^ubuntu$/basic/g' filename

(^ and $ characters represents begin and end of line).

edit flag offensive delete link more

Question Tools

1 follower


Asked: 2014-10-25 15:41:57 -0600

Seen: 193 times

Last updated: Oct 26 '14