LinuxQuestions.org
Share your knowledge at the LQ Wiki.
Home Forums Tutorials Articles Register
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, 08: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, 08:17 AM   #2
pan64
LQ Addict
 
Registered: Mar 2012
Location: Hungary
Distribution: debian/ubuntu/suse ...
Posts: 21,830

Rep: Reputation: 7308Reputation: 7308Reputation: 7308Reputation: 7308Reputation: 7308Reputation: 7308Reputation: 7308Reputation: 7308Reputation: 7308Reputation: 7308Reputation: 7308
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, 08:41 AM   #3
Turbocapitalist
LQ Guru
 
Registered: Apr 2005
Distribution: Linux Mint, Devuan, OpenBSD
Posts: 7,306
Blog Entries: 3

Rep: Reputation: 3720Reputation: 3720Reputation: 3720Reputation: 3720Reputation: 3720Reputation: 3720Reputation: 3720Reputation: 3720Reputation: 3720Reputation: 3720Reputation: 3720
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, 04:21 PM   #4
MadeInGermany
Senior Member
 
Registered: Dec 2011
Location: Simplicity
Posts: 2,789

Rep: Reputation: 1201Reputation: 1201Reputation: 1201Reputation: 1201Reputation: 1201Reputation: 1201Reputation: 1201Reputation: 1201Reputation: 1201
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



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 07:25 PM
Deleting a line with Nth occurence of anything. Eros He Linux - Newbie 10 09-30-2017 11:10 AM
[SOLVED] grep for pattern following the nth occurence of a character in a file cosminel Linux - Newbie 24 10-08-2013 02:34 AM

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

All times are GMT -5. The time now is 05:35 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
Open Source Consulting | Domain Registration