Issue
I am struggling with a sed command. I am trying to achieve this:
Input: 03:23PM
Output: 15:23PM
My sed command which I have tried:
echo $line | sed 's/03:..PM/15:..PM/g
Solution
To remember part of the replacement test, use parentheses. To refer to the first pair of parentheses, use \1
:
sed 's/03:\(..\)PM/15:\1PM/g'
In fact, you can make both the :
and PM
part of the capture group:
sed 's/03\(:..PM\)/15\1/g'
Answered By - choroba Answer Checked By - Terry (WPSolving Volunteer)