Teja
Teja

Reputation: 13544

Splitting lines based on a delimiter in UNIX

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

Upvotes: 9

Views: 19915

Answers (2)

twalberg
twalberg

Reputation: 62519

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'

Upvotes: 21

John Gaines Jr.
John Gaines Jr.

Reputation: 11554

xargs is a simple single program you can use to do this, as in:

$ echo "ALB|1001|2012-04-15 ALB|1001|2012-04-14 ALB|1001|2012-04-16 ALB|1001|2012-04-17"|xargs -d' ' -n1
ALB|1001|2012-04-15
ALB|1001|2012-04-14
ALB|1001|2012-04-16
ALB|1001|2012-04-17

Upvotes: 9

Related Questions