FG
💻 Software

Sed only print matched expression

Fresh7 days ago
Mar 15, 202635716 views
Confidence Score0%
0%

Problem

How to make sed only print the matched expression? I want to rewrite strings like "Battery 0: Charging, 44%, charging" to "Battery: 44%". I tried the following: This doesn't work. The common "solution" out there is to use search and replace and match the whole line: Now the .* are too greedy and th…

Error Output

sed -n '/\([0-9]*%\)/c Battery: \1'

Unverified for your environment

Select your OS to check compatibility.

1 Fix

Canonical Fix
Unverified Fix
New Fix – Awaiting Verification

Fix for: Sed only print matched expression

Low Risk

Make the regexp a little more specific. Pick a different tool. (just for the record, is shorthand for .)

Awaiting Verification

Be the first to verify this fix

Sign in to verify this fix

Environment