Replacing every 10th pipe with new line in unix
- by user327958
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!