Blesson Mathew
Blesson Mathew

Reputation: 17

How to do a reverse search in shell script

I am trying to do a search and replace on a string, doing a backward search on the pattern in shell script.

I have tried with the below, but it is not working for me

sed -r 's/ $/,/'

I am trying to apply this search and replace on a file having content like below

0 1 2 Comp level

I want the third space to be replaced with a comma

output should be like

0 1 2,Comp level

Upvotes: 0

Views: 417

Answers (1)

Cyrus
Cyrus

Reputation: 88583

To replace third space by ,:

 echo '0 1 2 Comp level' | sed 's/ /,/3'

Output:

0 1 2,Comp level

Upvotes: 1

Related Questions