How To Transpose Row Into Column In A Text File ...

How To Transpose Row Into Column In A Text File ...

Post by Administrat » Sat, 17 Jul 1999 04:00:00



Hi All,
        Can anyone tell me what is the best way to transpose a text file which
has something like the following:
ABC1 DEF2 GHI3 JKL4 MNO5

into the following (one word per line):

ABC1
DEF2
GHI3
JKL4
MNO5

Thanks in advance

 
 
 

How To Transpose Row Into Column In A Text File ...

Post by koll » Sat, 17 Jul 1999 04:00:00


use AWK ,
Quote:>Hi All,
> Can anyone tell me what is the best way to transpose a text file which
>has something like the following:
>ABC1 DEF2 GHI3 JKL4 MNO5

>into the following (one word per line):

>ABC1
>DEF2
>GHI3
>JKL4
>MNO5

>Thanks in advance


 
 
 

How To Transpose Row Into Column In A Text File ...

Post by Ken Pizzi » Sat, 17 Jul 1999 04:00:00


On 16 Jul 1999 02:27:55 GMT,


>    Can anyone tell me what is the best way to transpose a text file which
>has something like the following:
>ABC1 DEF2 GHI3 JKL4 MNO5

>into the following (one word per line):

>ABC1
>DEF2
>GHI3
>JKL4
>MNO5

tr ' ' '\012' <file

                --Ken Pizzini

 
 
 

How To Transpose Row Into Column In A Text File ...

Post by Ed All » Sat, 17 Jul 1999 04:00:00



>use AWK ,

>>Hi All,
>> Can anyone tell me what is the best way to transpose a text file which
>>has something like the following:
>>ABC1 DEF2 GHI3 JKL4 MNO5

>>into the following (one word per line):

>>ABC1
>>DEF2
>>GHI3
>>JKL4
>>MNO5

>>Thanks in advance

That is overkill.  Please don't put your followups before
what you are referring to.

Try this instead:

tr ' ' '\012' <textfile >transposed

Much faster than awk and won't care if the lines in the file are extremely
long.

 
 
 

How To Transpose Row Into Column In A Text File ...

Post by William Roede » Sat, 17 Jul 1999 04:00:00



> use AWK ,

> >Hi All,
> > Can anyone tell me what is the best way to transpose a text file which
> >has something like the following:
> >ABC1 DEF2 GHI3 JKL4 MNO5

> >into the following (one word per line):

> >ABC1
> >DEF2
> >GHI3
> >JKL4
> >MNO5

> >Thanks in advance

awk '{for(i=1;i<=NF;++i){print $i}}'
or
fmt -1
--
   __             _ __                    Here lies Lester Moore. Four
  /  )     /  /  ' )  )          /        shots from a 44. No Les, no
 /--'  *  /  /    /--' _ _ /> _ /  _  __  Moore. --Tombstone, Arizona

 
 
 

How To Transpose Row Into Column In A Text File ...

Post by Alex Vinoku » Tue, 20 Jul 1999 04:00:00




Quote:> Hi All,
>    Can anyone tell me what is the best way to transpose a text file
which
> has something like the following:
> ABC1 DEF2 GHI3 JKL4 MNO5

> into the following (one word per line):

> ABC1
> DEF2
> GHI3
> JKL4
> MNO5

> Thanks in advance

echo `cat filename`

        Alex

Sent via Deja.com http://www.deja.com/
Share what you know. Learn what you don't.

 
 
 

How To Transpose Row Into Column In A Text File ...

Post by Ron DuFresn » Tue, 20 Jul 1999 04:00:00





:> Hi All,
:>   Can anyone tell me what is the best way to transpose a text file
: which
:> has something like the following:
:> ABC1 DEF2 GHI3 JKL4 MNO5
:>
:> into the following (one word per line):
:>
:> ABC1
:> DEF2
:> GHI3
:> JKL4
:> MNO5
:>
:> Thanks in advance
:>
:>

: echo `cat filename`

Alex this is not what the user seeks I do not think, but, what the user
might be looking for is this:

NAME
       rot - rotate a file

SYNOPSIS
       rot [-rbloB] [-c c] [file]

DESCRIPTION
       Rot  rotates a file, so that lines become columns and vice
       versa. Without any  options,  the  file  will  be  rotated
       clockwise. So, from the input...

Laterer,

Ron DuFresne
--
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
"Cutting the space budget really restores my faith in humanity.  It
eliminates dreams, goals, and ideals and lets us get straight to the
business of hate, debauchery, and self-annihilation." -- Johnny Hart
        ***testing, only testing, and damn good at it too!***

OK, so you're a Ph.D.  Just don't touch anything.

 
 
 

How To Transpose Row Into Column In A Text File ...

Post by Dan Merc » Tue, 20 Jul 1999 04:00:00





>> use AWK ,

>> >Hi All,
>> > Can anyone tell me what is the best way to transpose a text file which
>> >has something like the following:
>> >ABC1 DEF2 GHI3 JKL4 MNO5

>> >into the following (one word per line):

>> >ABC1
>> >DEF2
>> >GHI3
>> >JKL4
>> >MNO5

>> >Thanks in advance

> awk '{for(i=1;i<=NF;++i){print $i}}'
> or
> fmt -1

Overkill:

Bourne:

   for in in `cat $file`;do echo "$i";done

Ksh:

   for i in $(<file);do print -- "$i";done

or even:

   set -A A -- $(<file);IFS=${IFS#??};print -- "${A[*]}"

Tr:

   tr ' ' '\012' <file

--
Dan Mercer

Opinions expressed herein are my own and may not represent those of my employer.

 
 
 

How To Transpose Row Into Column In A Text File ...

Post by Slawek Za » Tue, 20 Jul 1999 04:00:00



Ron> : echo `cat filename`

Ron> Alex this is not what the user seeks I do not think, but, what
Ron> the user might be looking for is this:
[desc. of rot command snipped]
You may not have this on your system (I don't :) so try this:
tr -s "[ \t]" "\n" < <your-file-name>
--
Straight Edge ? Sounds ok to me, but only if I could smoke, drink ...

 
 
 

How To Transpose Row Into Column In A Text File ...

Post by Trey Aske » Tue, 20 Jul 1999 04:00:00


Well I suppose you could doing something like the following:

#cat filename | tr ' ' '\n' > newfile
#mv newfile filename

You could also use sed, perl, etc....




> > Hi All,
> >       Can anyone tell me what is the best way to transpose a text file
> which
> > has something like the following:
> > ABC1 DEF2 GHI3 JKL4 MNO5

> > into the following (one word per line):

> > ABC1
> > DEF2
> > GHI3
> > JKL4
> > MNO5

> > Thanks in advance

> echo `cat filename`

>         Alex

> Sent via Deja.com http://www.deja.com/
> Share what you know. Learn what you don't.

 
 
 

How To Transpose Row Into Column In A Text File ...

Post by Alex Vinoku » Wed, 21 Jul 1999 04:00:00








> :> Hi All,
> :>      Can anyone tell me what is the best way to transpose a text file
> : which
> :> has something like the following:
> :> ABC1 DEF2 GHI3 JKL4 MNO5
> :>
> :> into the following (one word per line):
> :>
> :> ABC1
> :> DEF2
> :> GHI3
> :> JKL4
> :> MNO5
> :>
> :> Thanks in advance
> :>
> :>

> : echo `cat filename`

> Alex this is not what the user seeks I do not think,

  Why not?

Here is a file named xxx :

AAA
BBB
CCC
DDD

Here is a command line :

echo `cat xxx` > yyy

Now we have a file yyy as follwing :

AAA BBB CCC DDD.

By the way, we can also use the following command line:

cat filename | xargs echo

- Show quoted text -

Quote:> but, what the user
> might be looking for is this:

> NAME
>        rot - rotate a file

> SYNOPSIS
>        rot [-rbloB] [-c c] [file]

> DESCRIPTION
>        Rot  rotates a file, so that lines become columns and vice
>        versa. Without any  options,  the  file  will  be  rotated
>        clockwise. So, from the input...

> Laterer,

What operating system are you using?
My system (Sun0S 5.6) hasn't got the rot command.

Quote:> Ron DuFresne
> --
> ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
> "Cutting the space budget really restores my faith in humanity.  It
> eliminates dreams, goals, and ideals and lets us get straight to the
> business of hate, debauchery, and self-annihilation." -- Johnny Hart
>    ***testing, only testing, and damn good at it too!***

> OK, so you're a Ph.D.  Just don't touch anything.

Thank you very much for yor answer and information.

        Alex

Sent via Deja.com http://www.deja.com/
Share what you know. Learn what you don't.

 
 
 

How To Transpose Row Into Column In A Text File ...

Post by Dan Merc » Wed, 21 Jul 1999 04:00:00










>> :> Hi All,
>> :>  Can anyone tell me what is the best way to transpose a text file
>> : which
>> :> has something like the following:
>> :> ABC1 DEF2 GHI3 JKL4 MNO5
>> :>
>> :> into the following (one word per line):
>> :>
>> :> ABC1
>> :> DEF2
>> :> GHI3
>> :> JKL4
>> :> MNO5
>> :>
>> :> Thanks in advance
>> :>
>> :>

>> : echo `cat filename`

>> Alex this is not what the user seeks I do not think,

>   Why not?

> Here is a file named xxx :

> AAA
> BBB
> CCC
> DDD

> Here is a command line :

> echo `cat xxx` > yyy

> Now we have a file yyy as follwing :

> AAA BBB CCC DDD.

Except he said he was starting with "AAA BBB CCC DDD" and wanted to
get to:

AAA
BBB
CCC
DDD

which "echo `cat filename`" won't do.

--
Dan Mercer

- Show quoted text -

Quote:

> By the way, we can also use the following command line:

> cat filename | xargs echo

>> but, what the user
>> might be looking for is this:

>> NAME
>>        rot - rotate a file

>> SYNOPSIS
>>        rot [-rbloB] [-c c] [file]

>> DESCRIPTION
>>        Rot  rotates a file, so that lines become columns and vice
>>        versa. Without any  options,  the  file  will  be  rotated
>>        clockwise. So, from the input...

>> Laterer,

> What operating system are you using?
> My system (Sun0S 5.6) hasn't got the rot command.
>> Ron DuFresne
>> --
>> ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
>> "Cutting the space budget really restores my faith in humanity.  It
>> eliminates dreams, goals, and ideals and lets us get straight to the
>> business of hate, debauchery, and self-annihilation." -- Johnny Hart
>>        ***testing, only testing, and damn good at it too!***

>> OK, so you're a Ph.D.  Just don't touch anything.

> Thank you very much for yor answer and information.

>    Alex

> Sent via Deja.com http://www.deja.com/
> Share what you know. Learn what you don't.

Opinions expressed herein are my own and may not represent those of my employer.
 
 
 

How To Transpose Row Into Column In A Text File ...

Post by Alex Vinoku » Thu, 22 Jul 1999 04:00:00








> >> In comp.unix.questions Alex Vinokur





> >> :> Hi All,
> >> :>     Can anyone tell me what is the best way to transpose a text
file
> >> : which
> >> :> has something like the following:
> >> :> ABC1 DEF2 GHI3 JKL4 MNO5
> >> :>
> >> :> into the following (one word per line):
> >> :>
> >> :> ABC1
> >> :> DEF2
> >> :> GHI3
> >> :> JKL4
> >> :> MNO5
> >> :>
> >> :> Thanks in advance
> >> :>
> >> :>

> >> : echo `cat filename`

> >> Alex this is not what the user seeks I do not think,

   You are right.
   Sorry, my inattention.
   What I did is reverse task.

- Show quoted text -

Quote:

> >   Why not?

> > Here is a file named xxx :

> > AAA
> > BBB
> > CCC
> > DDD

> > Here is a command line :

> > echo `cat xxx` > yyy

> > Now we have a file yyy as follwing :

> > AAA BBB CCC DDD.

> Except he said he was starting with "AAA BBB CCC DDD" and wanted to
> get to:

> AAA
> BBB
> CCC
> DDD

> which "echo `cat filename`" won't do.

You are right.
   Sorry, my inattention.

> --
> Dan Mercer


[snip]

        Thank you very much.
        Alex

Sent via Deja.com http://www.deja.com/
Share what you know. Learn what you don't.

 
 
 

How To Transpose Row Into Column In A Text File ...

Post by Renau » Thu, 22 Jul 1999 04:00:00


Slawek Zak a crit:

Quote:> You may not have this on your system (I don't :) so try this:
> tr -s "[ \t]" "\n" < <your-file-name>

Well, were u straight Edged or EggNogged ???

this'd do better :
tr -s "[ \t]" "\n\n" < your-file-name

Quote:> --
> Straight Edge ? Sounds ok to me, but only if I could smoke, drink ...

 
 
 

How To Transpose Row Into Column In A Text File ...

Post by Slawek Za » Mon, 02 Aug 1999 04:00:00


    Renaud> X-Mailer: Mozilla 4.06 [fr] (Win95; I)
...
    Renaud> Slawek Zak a crit:

    We do speak english here, and use UNIX, not windows.

    >> You may not have this on your system (I don't :) so try this:
    >> tr -s "[ \t]" "\n" < <your-file-name>

    Renaud> Well, were u straight Edged or EggNogged ???
    Frog toasted (is it english, anyways ?)

    Renaud> this'd do better : tr -s "[ \t]" "\n\n" < your-file-name

Nonsense, -s makes tr squeeze multiple character occurence, and [ \t]
stands for character class, so single char '\n' is just about
enough. Didn't it work for yOU ? (just curious)

--
You've been chrooted to hell, boy. Nothing but pain and suffering in
this endless maze of uncertainty.