Search code examples
unixmultiple-columnsseparator

Separate columns by a specific character unix


I have a file where are listed books like this:

047143003X|Financial Risk Management Handbook, 2ed (GARP)|Philippe Jorion|John Wiley|581

0471354619|Handbook of Organization Theory|Haridimos Tsoukas|Oxford|419

.........

How can I display them as:

047143003X

Financial Risk Management Handbook, 2ed (GARP)

Philippe Jorion

John Wiley

581

0471354619

Handbook of Organization Theory

Haridimos Tsoukas

Oxford

419

Solution

  • You can use sed for that.

    sed 's@|@\n\n@g' < books.txt
    

    If, however, you're fine with 1:1 character mappings, you can even use tr:

    tr '|' '\n' < books.txt