regex


Using Bash Regular Expressions to replace part of matched results


I have a file with lines that appear as:
1/foo/bar/
2/foo/bar/
3/foo/bar/
I would like to take two inputs, the first of which to match to the number. This is relatively simple. Then, I'd like to replace 'bar' with whatever is input for the second argument. Is this possible?
This smells like a homework assignment, but anyway, if you're on Linux (bash) "sed" should be available to match a line and do a replacement in that line, otherwise passing through non-matching lines unchanged.

Related Links

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
How to detect a string which does not include " using flex?
Extract certain values from string in .txt files with PowerShell
Apache 301 Redirect Add language prefix if not present
Regex, match characters and doesn't contain more than one _ followed by another _
Regex ignore word
Regex not valid in google sheets error?
extract substring using regex in shell script

Categories

HOME
regex
odoo-10
vb.net
gwt
lua
elf
apacheds
oracle-adf
whitespace
add-in
drag
hadoop2
android-vision
doorkeeper
graphengine
axure
google-cloud-sdk
avr
group-by
jsqmessagesviewcontroller
w2ui
atmelstudio
gas
spring-restdocs
slime
hough-transform
core-location
regex-group
text-parsing
angular-ngmodel
flatbuffers
webfocus
apscheduler
dapper-fastcrud
webcenter
folly
nio
perl-module
flags
cookiestore
amazon-vpc
plasticscm
codeigniter-hmvc
karnaugh-map
strip-tags
openwebanalytics
autogen
assembly-references
mailcore2
mink
flattr
statistics-bootstrap
building
ocsp
rsh
insert-update
cufft
uiswitch
okuma
clientid
materialdrawer
interpreted-language
text-alignment
session-replication
equinox
translucency
dhc
llvm-gcc
mks
spiceworks
jet.com-apis
cpp-netlib
dynamic-data-display
eventmachine
bonecp
sonata-media-bundle
nawk
floating-point-conversion
jflow
neventstore
impdp
sender
gigaspaces
guvnor
rpn
jsr223
obout
self-organizing-maps
sharepoint-timer-job
jtemplates
android-3.1
sloc
dynamic-websites
development-machine
ants
reference-library

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