Splitting lines based on a delimiter in UNIX Splitting lines based on a delimiter in UNIX unix unix

Splitting lines based on a delimiter in UNIX


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'


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' ' -n1ALB|1001|2012-04-15ALB|1001|2012-04-14ALB|1001|2012-04-16ALB|1001|2012-04-17