Replacing every 10th pipe with new line in unix

Posted by user327958 on Super User See other posts from Super User or by user327958
Published on 2014-05-30T13:52:33Z Indexed on 2014/05/30 15:35 UTC
Read the original article Hit count: 151

Filed under:
|
|
|
|

Lets say I have fields:

name, number, id

I have a data file:

name1|number1|id1|name2|number2|id2...etc

I want to replace every 3rd pipe with a new line or '\n' so I get:

name1|number1|id1  
name2|number2|id2  

I'm having no luck with awk or sed.

I've tried the following, and variations of:

awk '/"\|"/{c++;if(c==10){sub("\|","\n");c=0}}1' inputfile.txt  
sed 's/"|"/"\n"/2' inputfile.txt  

It tells me awk:

syntax error near line 1

awk: illegal statement near line 1

awk: syntax error near line 1

awk: bailing out near line 1

Any help is greatly appreciated!

EDIT: Thank you!

© Super User or respective owner

Related posts about linux

Related posts about command-line