PHPFixing
  • Privacy Policy
  • TOS
  • Ask Question
  • Contact Us
  • Home
  • PHP
  • Programming
  • SQL Injection
  • Web3.0

Thursday, November 10, 2022

[FIXED] How to replace certain position after match using sed in Ubuntu?

 November 10, 2022     bash, linux, redhat, sed, ubuntu     No comments   

Issue

I have a line I want to replace such as

'baseurl' => 'https://231.231.231.231'

But I only want it to replace the https://231.231.231.231 part.

Basically I want it to be

'baseurl' => 'myvaluehere'

I have tried sudo sed -i "s|'baseurl'|${value1}|g" file.php

How do I replace after certain characters after 'baseurl' is matched?


Solution

Using sed

$ sed -E "/(baseurl'[^']*')[^']*/s//\1myvaluehere/" input_file
'baseurl' => 'myvaluehere'


Answered By - HatLess
Answer Checked By - David Goodson (PHPFixing Volunteer)
  • Share This:  
  •  Facebook
  •  Twitter
  •  Stumble
  •  Digg
Newer Post Older Post Home

0 Comments:

Post a Comment

Note: Only a member of this blog may post a comment.

Total Pageviews

Featured Post

Why Learn PHP Programming

Why Learn PHP Programming A widely-used open source scripting language PHP is one of the most popular programming languages in the world. It...

Subscribe To

Posts
Atom
Posts
Comments
Atom
Comments

Copyright © PHPFixing