regex


Replace a line in the file using sed, line has a moving portion in the center of it


There is a moving portion in the line.
sed needs to search for a line that might have anything in the center of it.
In other words we are looking to find this line by telling sed that it starts with
aaa
and ends with
ccc
the center could be anything.
Let's say we have a file called a.txt, and this is what is in it.
a
b
aaa111ccc
sed needs to find the line that looks like..
aaa(.*)ccc
And then replace it with
"_TEST_"
The output should be aaa_TEST_bbb
Which part do you need help with?
sed 's/^aaa.*bbb$/aaa_TEST_bbb/' file >newfile
If you want to edit the file in place, remove the redirection and add a suitable -i option (provided your sed supports it).

Related Links

strip a regex character match from a string
Replacement within the matched string with sed
AHK - How to use dynamic hotstring with a barcode scanner
Fuzzy match on google sheets
VB Net RegEx Match Multiple
Invalid Escape Character in Regex for html 5 Input Validation
Regex to match start and end line [duplicate]
How to handle “cannot refer to an open group at position” in Python?
How to format the output of a grep with a regex pattern to match between a string and character
Regular expression to match a line containing only the list of words
How do I create a regex for 2 different patterns that outputs in 1 group, in Google sheets?
Replacing a string in between known strings over mutiple lines in Powershell
Data Preperation Identify String using Regex and move to new column
Regular expressions - optional brackets
ICU Regex matching for non-digit and no whitespace
Seemingly incorrect regex evaluation in regexp_replace

Categories

HOME
math
bootstrap-4
gwt
compliance
pyqt5
servlets
python-3.5
fonts
android-sms
addeventlistener
winsql
sweetalert
telerik
eps
luci
facebook-opengraph
avr
raspberry-pi2
afnetworking-2
watchservice
amplitude
orientdb-2.1
gas
cmusphinx
rational
hp-alm
jscodeshift
centroid
amazon-cloudfront
missingmethodexception
jqplot
dsl
structure
physics
simple-html-dom
mediacodec
nest-thermostat
imageshack
capstone
deep-copy
roo
folly
confirm
decompiler
apartment-gem
vtable
transpose
jupyter-irkernel
jsonstore
easy-digital-downloads
mdanalysis
tabview
karnaugh-map
recurrence
column-oriented
netbeans-7
asp.net-mvc-custom-filter
blocking
informatica-cloud
error-correction
directsound
singly-linked-list
network-traffic
menustrip
rras
ane
openocd
ubiquity
axlsx
node-orm2
realm-list
linegraph
android-print-framework
data-science-studio
targetinvocationexception
openxls
setattribute
jasmin
razor-2
django-postgresql
asf
iphone-privateapi
zeroclipboard
email-spam
custom-titlebar
acts-as-taggable-on
notifyicon
transport-stream
gora
capitalize
adlds
locomotivejs
timespan
domain-mapping
arden-syntax
xml-dtd
j#
intel-8080
ruby-1.9.2
katta
system-tray
non-relational-database
run-length-encoding

Resources

Mobile Apps Dev
Database Users
javascript
java
csharp
php
android
MS Developer
developer works
python
ios
c
html
jquery
RDBMS discuss
Cloud Virtualization
Database Dev&Adm
javascript
java
csharp
php
python
android
jquery
ruby
ios
html
Mobile App
Mobile App
Mobile App