Search
 
SCRIPT & CODE EXAMPLE
 

SHELL

Using sed to find and replace complex string (preferrably with regex)

$ sed -e '1s/name/something/2' 
      -e '3s/name/somethingdifferent/2' 
      -e 's/password/somethingelse/2' sample.xml
Comment

Using sed to find and replace complex string (preferrably with regex)

sed -i -E "s/(<username>.+)name(.+</username>)/1something2/" file.xml
Comment

Using sed to find and replace complex string (preferrably with regex)

sed -i -E "s/(<username>.+)name(.+</username>)/1something2/" file.xml
This is, I think, what you're looking for.

Explanation:

parentheses in the first part define groups (strings in fact) that can be reused in the second part
1, 2, etc. in the second part are references to the i-th group captured in the first part (the numbering starts with 1)
-E enables extended regular expressions (needed for + and grouping).
-i enables "in-place" file edit mode
Comment

Using sed to find and replace complex string (preferrably with regex)

sed -e '/username/s/CDATA[name]/CDATA[something]/' 
-e '/password/s/CDATA[password]/CDATA[somethingelse]/' 
-e '/dbname/s/CDATA[name]/CDATA[somethingdifferent]/' file.txt
Comment

PREVIOUS NEXT
Code Example
Shell :: Quick start: Use as a GitHub Pages remote theme 
Shell :: git switch to specific branch name 
Shell :: mnet - git config user 
Shell :: curl output readable json 
Shell :: git init bare initialize empty git repository 
Shell :: threshold 
Shell :: bind mac to AD via JAMF with policy* 
Shell :: vscode find all @media 
Shell :: How To create the SHA1 sum hash digest and save it to a file 
Shell :: Docker linuxmint how to 
Shell :: allow ssh connections through windows defender 
Shell :: lightsail get plesk password 
Shell :: digi4school downloader 
Shell :: node_modules permission mkdir 
Shell :: Update or Remove Single Entry from Known Hosts 
Shell :: how to download bangla font in ubuntu 
Shell :: find and rm files 
Shell :: eslint ignore pattern multiple patterns 
Shell :: systemd service after internet connection 
Shell :: format volume diskpart 
Shell :: start adb exe manually if necessary 
Shell :: jenkins pipeline for sonarqube 
Shell :: hxselect examples 
Shell :: how to retain ownership permissions when copying file linux 
Shell :: how to close git issue with fixes automaticallt 
Shell :: metasploit msf commands kali linux 
Shell :: git edit hunk how to remove + lines 
Shell :: clamscan version command 
Shell :: jetson nano 4.3 TRT 
Shell :: filmora turn off message center 
ADD CONTENT
Topic
Content
Source link
Name
6+2 =