regex


Replacing strings in files with regex


I've manually removed some superfluous //-------------------------------------
comments from all c++ files within a folder and its subfolders here .
Now I thought that it might be possible to replace "//<unknown number of dashes><line break>" with an empty string or a line break via a shell script.
Afterwards I'd want to replace three consecutive line breaks with two line breaks.
Could someone tell me how to achieve this with a shell script?
To remove all C++ style comments that contain only dashes and optional trailing whitespace:
sed 's|//--* *$||' -i file.cpp
To remove trailing whitespace:
sed 's/ *$//' -i file.cpp
I added SzG's command to this one to get it to run recursively:
find . -name '*.cxx' | xargs sed 's|// --* *$||' -i

Related Links

Functions on regexp_replace result in Postgres
RegEx to match 2-digit number in certain range
Regex Memorize all matches before replace
Modify formula stored in string via VBA
Regex for anything but multicharacter token
.tsv Output file not importing correctly in Hive
Inserting a char at particular index of line(s) in a file using awk or sed
HiveQL - extract regular expression that matches a pattern at the end of the string
Extracting sentences in R
Regex: How can I match third IPv4 address?
sed delete trailing pattern of digits
Verifying address using regular expression
yytext contains characters not in match
This regex_match function is not working correctly error code 7
Target file names using Regex
How to remove specific information from a line in txt

Categories

HOME
regex
flutter
html5-canvas
svg
word-vba
xquery
sweetalert
phpmailer
coded-ui-tests
hyperion
signature
oracle-agile-plm
postgresql-9.5
apex
accumulo
gitlab-ci-runner
jmeter-plugins
spark-graphx
deadbolt
netcdf
shape
esri
physics
scalability
mediacodec
codewarrior
kprobe
json-c
stomp
chai
jdk1.6
p4-lang
qweb
runge-kutta
es6-promise
permgen
monogame
msysgit
oracle-aq
zuul
http-status-code-500
mrtg
htc
javascript-security
billing
flying-saucer
a-star
kie-workbench
plotrix
wxhaskell
tfs2008
android-chips
heritrix
ios-frameworks
bash-completion
gcloud-java
okuma
trello.net
occam-pi
domo
many-to-one
julian
user-registration
realm-list
ppl
google-swiffy
epplus-4
gcovr
opensc
jet.com-apis
dynamic-data-display
tinkerpop-frames
email-spam
xsltforms
notifyicon
nawk
libtorrent-rasterbar
sysadmin
xhtml-transitional
12factor
domain-mapping
file-structure
lungojs
sticky-footer
cellid
azure-role-environment
postgresql-8.1
boost-gil
demoscene
coolstorage
remote-control
shareware
corporate-policy
case-tools

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