You are not logged in.

#1 2005-04-13 05:43:39

rasat
Forum Fellow
From: Finland
Registered: 2002-12-27
Posts: 2,296
Website

list of words in a row to column?

How to change in text file to display each words in one column.

test0 test1 test2 test3

test0
test1
test2
test3


Markku

Offline

#2 2005-04-13 06:11:12

cactus
Taco Eater
From: t͈̫̹ͨa͖͕͎̱͈ͨ͆ć̥̖̝o̫̫̼s͈̭̱̞͍̃!̰
Registered: 2004-05-25
Posts: 4,622
Website

Re: list of words in a row to column?

if you know then are always space seperated, and all there is is a list needing to be converted into a column..

tr ' ' 'n'

then just pipe the text through it..

cat file | tr ' ' 'n'

There are a myriad of other ways to do it, and coutless others depending on the utilities/programming languages, chosen.


"Be conservative in what you send; be liberal in what you accept." -- Postel's Law
"tacos" -- Cactus' Law
"t̥͍͎̪̪͗a̴̻̩͈͚ͨc̠o̩̙͈ͫͅs͙͎̙͊ ͔͇̫̜t͎̳̀a̜̞̗ͩc̗͍͚o̲̯̿s̖̣̤̙͌ ̖̜̈ț̰̫͓ạ̪͖̳c̲͎͕̰̯̃̈o͉ͅs̪ͪ ̜̻̖̜͕" -- -̖͚̫̙̓-̺̠͇ͤ̃ ̜̪̜ͯZ͔̗̭̞ͪA̝͈̙͖̩L͉̠̺͓G̙̞̦͖O̳̗͍

Offline

#3 2005-04-13 07:51:30

rasat
Forum Fellow
From: Finland
Registered: 2002-12-27
Posts: 2,296
Website

Re: list of words in a row to column?

cactus wrote:
cat file | tr ' ' 'n'

Thanks!


Markku

Offline

#4 2005-04-13 14:55:21

phrakture
Arch Overlord
From: behind you
Registered: 2003-10-29
Posts: 7,879
Website

Re: list of words in a row to column?

sed "s/s*/n/g" file

might work too... and that will work on any number of whitespaces (tabs, spaces, etc)

Offline

#5 2005-04-13 15:16:15

rasat
Forum Fellow
From: Finland
Registered: 2002-12-27
Posts: 2,296
Website

Re: list of words in a row to column?

Works too well. wink

[rasat@localhost /]$ sed "s/s*/n/g" test.tmp

t
e
s
t
t
e
s
t
1
t
e
s
t
2

[rasat@localhost /]$


Markku

Offline

#6 2005-04-13 17:08:36

phrakture
Arch Overlord
From: behind you
Registered: 2003-10-29
Posts: 7,879
Website

Re: list of words in a row to column?

what the? what is "s"? am I backwards... maybe you you want "w"? I dunno... I'll have to bust out my sed reference later...

Offline

#7 2005-04-13 18:29:59

cactus
Taco Eater
From: t͈̫̹ͨa͖͕͎̱͈ͨ͆ć̥̖̝o̫̫̼s͈̭̱̞͍̃!̰
Registered: 2004-05-25
Posts: 4,622
Website

Re: list of words in a row to column?

you want a plus instead of a star phrakture. Star also matches 0 occurances. Plus is one or more.


"Be conservative in what you send; be liberal in what you accept." -- Postel's Law
"tacos" -- Cactus' Law
"t̥͍͎̪̪͗a̴̻̩͈͚ͨc̠o̩̙͈ͫͅs͙͎̙͊ ͔͇̫̜t͎̳̀a̜̞̗ͩc̗͍͚o̲̯̿s̖̣̤̙͌ ̖̜̈ț̰̫͓ạ̪͖̳c̲͎͕̰̯̃̈o͉ͅs̪ͪ ̜̻̖̜͕" -- -̖͚̫̙̓-̺̠͇ͤ̃ ̜̪̜ͯZ͔̗̭̞ͪA̝͈̙͖̩L͉̠̺͓G̙̞̦͖O̳̗͍

Offline

#8 2005-04-13 19:35:23

phrakture
Arch Overlord
From: behind you
Registered: 2003-10-29
Posts: 7,879
Website

Re: list of words in a row to column?

Ahhhh... that's it...

sed "s/s+/n/g" file

Offline

#9 2005-04-14 02:45:51

rasat
Forum Fellow
From: Finland
Registered: 2002-12-27
Posts: 2,296
Website

Re: list of words in a row to column?

No plus or star does the job.
sed "s/s/n/g"


Markku

Offline

#10 2005-04-14 02:58:27

phrakture
Arch Overlord
From: behind you
Registered: 2003-10-29
Posts: 7,879
Website

Re: list of words in a row to column?

yeah, but that only works for a single whitespace.... try two spaces and you'll get multiple newlines...

Offline

#11 2010-06-24 00:18:07

lel7lel7
Member
Registered: 2010-06-24
Posts: 1

Re: list of words in a row to column?

Hi,
These codes have not worked for me, i am unsure why...
My data is in the form..

[lg45@dev64-mgmt ~]$ echo $start
25293633 7393500 10578865 25293623 122206254 26797134 41906484

but i have also tried saving it as a new file 'nano.txt' - either way the sed and "tr '' 'n'" methods give me random results such as
n2n5n2n9n3n6n3n3n and 25293633n7393500n10578865n2...

Any suggestions would be great smile

Offline

#12 2010-06-24 00:22:52

andresp
Member
Registered: 2010-05-29
Posts: 62

Re: list of words in a row to column?

$ tr \  \\n <<<'25293633 7393500 10578865 25293623 122206254 26797134 41906484'

Offline

#13 2010-06-24 00:28:11

Procyon
Member
Registered: 2008-05-07
Posts: 1,819

Re: list of words in a row to column?

New forum software probably messed those posts up removing backslashes.

Putting the backslashes back:
echo a b c | tr ' ' '\n'
echo a b c | sed 's/\s\+/\n/g'

Offline

#14 2010-06-24 00:46:31

karol
Archivist
Registered: 2009-05-06
Posts: 25,440

Re: list of words in a row to column?

2005-04-14
ooooooooooooooooooold thread

Offline

#15 2010-06-24 01:21:25

Allan
Pacman
From: Brisbane, AU
Registered: 2007-06-09
Posts: 11,487
Website

Offline

Board footer

Powered by FluxBB