LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - General (https://www.linuxquestions.org/questions/linux-general-1/)
-   -   Replace after nth occurence (https://www.linuxquestions.org/questions/linux-general-1/replace-after-nth-occurence-4175619134/)

sampat19 12-07-2017 08:10 AM

Replace after nth occurence
 
Hi,

I need some help with following:

I have a file wich contains the following:

123;345;456;335;234;244;245;2345;234;234;345;

There are 11 semicolons in this, I would like to have an output where after the 8th semicolon all semicolons are replaced by space (" ") so the output will be:

123;345;456;335;234;244;245;2345;234 234 345

I tried some sed functions, but could not execute the proper command.

Hope you can help me out.

Thanks.

Sampat

pan64 12-07-2017 08:17 AM

would be nice to know what did you really try.
Probably you need to check the gnu sed (instead of the non-gnu version) it has some interesting extension.

Turbocapitalist 12-07-2017 08:41 AM

It's a little complicated in sed but easier in perl. Either way, can you show what you have tried so far so we can see where you need help?

MadeInGermany 12-07-2017 04:21 PM

Most easy with a loop
Code:

sed '
:L
s/;/ /9
t L
'

Substitute the 9th semicolon, repeat if successful.


All times are GMT -5. The time now is 08:17 AM.