Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Splitting lines based on a delimiter in UNIX

Tags:

string

unix

split

I have some data which is being returned by some SQL query which looks as below.I am trying to separate the lines based on a delimiter and send it to the new line.How can I do this in UNIX.. I tried using shell-scripting but couldn't make through...

ALB|1001|2012-04-15 ALB|1001|2012-04-14 ALB|1001|2012-04-16 ALB|1001|2012-04-17


ALB|1001|2012-04-15
ALB|1001|2012-04-14 
ALB|1001|2012-04-16 
ALB|1001|2012-04-17
like image 286
Teja Avatar asked May 17 '12 19:05

Teja


1 Answers

For that particular example, tr ' ' '\n' < file ought to work:

echo "ALB|1001|2012-04-15 ALB|1001|2012-04-14 ALB|1001|2012-04-16 ALB|1001|2012-04-17" | tr ' ' '\n'
like image 167
twalberg Avatar answered Oct 27 '22 13:10

twalberg