1

Let's say we have a file named profile.cfg containing the following:

user.name=Duvdevan
user.email=duvdevan@duvdevan.duv
user.web=http://duvdevan.duv
user.country=Bosnia/Herzegovina
user.age=26
user.biography="A web developer.\n\nLikes echo command..."

Now, I'd like to update contents of line three, the user.web property and place it in the same position as it is currently to keep above and bellow contents as they are.

All I have tried so far is: cat profile.cfg | grep user.web and I get the value of that line...

Zlatan Omerović
  • 3,863
  • 4
  • 39
  • 67

1 Answers1

4

You can do this easily using sed

$ sed 's#user.web=.*#user.web=http://NEW_DOMAIN#' file
user.name=Duvdevan
user.email=duvdevan@duvdevan.duv
user.web=http://NEW_DOMAIN
user.country=Bosnia/Herzegovina
user.age=26
user.biography="A web developer.\n\nLikes echo command..."

Use -i option to make inline changes to file so that no redirection is required.

nu11p01n73R
  • 26,397
  • 3
  • 39
  • 52