Search
 
SCRIPT & CODE EXAMPLE
 

SHELL

sed use match in replacement

For using match in sed replacement, just border it with '(' and ')':
echo Before123 | sed 's/Before([0-9]*)/1After/g'
123After	# number is matched withtin '( )' and replaced in '1'
Example with 2 match replacements
echo a_b | sed 's/(^.*)_(.*$)/first is 1 and 2 is after/g'
Comment

sed replace from match

Just use a similar example with using ".*" regex with sed as following:
sed 's/match_pattern.*/replacement_of_match_and_rest_of_line/' file.txt
Comment

PREVIOUS NEXT
Code Example
Shell :: How to install packages on arch linux 
Shell :: add package in pubspec.yaml using command prompt in flutter 
Shell :: git add untracked to gitignore 
Shell :: windows powershell mkdir multiple directories 
Shell :: command to return to old shell 
Shell :: get all changes on commit name 
Shell :: log the output of the terminal 
Shell :: sed output to file 
Shell :: aws cli cloudformation list stacks 
Shell :: linux command to show memory hardware 
Shell :: reverse a django migration 
Shell :: ssh key exchange 
Shell :: install gulp gulp-util exited with code 1 
Shell :: api to access gitlab varaible 
Shell :: git merge cherry pick 
Shell :: grep remove -- 
Shell :: how can I check memory usage in linux? 
Shell :: number all files in a folder 
Shell :: rpm uninstall package 
Shell :: create new branch 
Shell :: save command output 
Shell :: command to find out my git head version 
Shell :: basename bash 
Shell :: how to use git stash in current branch 
Shell :: bash if with function call 
Shell :: Add a Remote Repository in git command 
Shell :: bash start two processes at the same time 
Shell :: clear git bash window 
Shell :: restart service linux crontab 
Shell :: jenkins as docker container 
ADD CONTENT
Topic
Content
Source link
Name
9+6 =