LinuxQuestions.org
Welcome to the most active Linux Forum on the web.
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - General
User Name
Password
Linux - General This Linux forum is for general Linux questions and discussion.
If it is Linux Related and doesn't seem to fit in any other forum then this is the place.

Notices


Reply
  Search this Thread
Old 12-07-2017, 09:10 AM   #1
sampat19
LQ Newbie
 
Registered: Dec 2017
Posts: 1

Rep: Reputation: Disabled
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
 
Old 12-07-2017, 09:17 AM   #2
pan64
LQ Guru
 
Registered: Mar 2012
Location: Hungary
Distribution: debian/ubuntu/suse ...
Posts: 9,874

Rep: Reputation: 2907Reputation: 2907Reputation: 2907Reputation: 2907Reputation: 2907Reputation: 2907Reputation: 2907Reputation: 2907Reputation: 2907Reputation: 2907Reputation: 2907
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.
 
Old 12-07-2017, 09:41 AM   #3
Turbocapitalist
Senior Member
 
Registered: Apr 2005
Distribution: Ubuntu, Devuan, OpenBSD
Posts: 2,690
Blog Entries: 3

Rep: Reputation: 1167Reputation: 1167Reputation: 1167Reputation: 1167Reputation: 1167Reputation: 1167Reputation: 1167Reputation: 1167Reputation: 1167
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?
 
Old 12-07-2017, 05:21 PM   #4
MadeInGermany
Member
 
Registered: Dec 2011
Location: Simplicity
Posts: 528

Rep: Reputation: 249Reputation: 249Reputation: 249
Most easy with a loop
Code:
sed '
:L
s/;/ /9
t L
'
Substitute the 9th semicolon, repeat if successful.
 
1 members found this post helpful.
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
Change nth occurence in every line ufmale Programming 12 10-25-2017 08:25 PM
Deleting a line with Nth occurence of anything. Eros He Linux - Newbie 10 09-30-2017 12:10 PM
[SOLVED] grep for pattern following the nth occurence of a character in a file cosminel Linux - Newbie 24 10-08-2013 03:34 AM

LinuxQuestions.org > Forums > Linux Forums > Linux - General

All times are GMT -5. The time now is 01:19 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration