Sunday, April 28, 2024
68
rated 0 times [  68] [ 0]  / answers: 1 / hits: 128313  / 2 Years ago, wed, may 11, 2022, 8:36:57

I have simple text file named "example".



Reading with terminal command: cat example



Output:



abc cdef ghi jk lmnopq rst uv wxyz


I want to convert (transform) into following form: (expected output from cat example)



abc
cdef
ghi
jk
lmnopq
rst
uv
wxyz


How can I do this via the command-line?



(This is only an example file, I want to convert word's position in vertical-column)


More From » command-line

 Answers
2

A few choices:




  1. The classic, use tr:



    tr ' ' '
    ' < example

  2. Use cut



    cut -d ' ' --output-delimiter=$'
    ' -f 1- example

  3. Use sed



    sed 's/ /
    /g' example

  4. Use perl



    perl -pe 's/ /
    /g' example

  5. Use the shell



    foo=$(cat example); echo -e ${foo// /n}


[#25416] Friday, May 13, 2022, 2 Years  [reply] [flag answer]
Only authorized users can answer the question. Please sign in first, or register a free account.
itutejagua

Total Points: 89
Total Questions: 124
Total Answers: 113

Location: British Indian Ocean Territory
Member since Sun, Feb 13, 2022
2 Years ago
;