Find the answer to your Linux question:
Results 1 to 4 of 4
ok, her e is the situation. I have a text file: column A seperator Column B 1 : A 2 : B etc. I want to convert it to rows, ...
  1. #1
    Just Joined!
    Join Date
    Mar 2009
    Posts
    2

    File / text maniplation

    ok, her e is the situation.

    I have a text file:

    column A seperator Column B
    1 : A
    2 : B

    etc.

    I want to convert it to rows, where Column A is the first line, and column B is the second line.

    Is there an easy way to do this?

    thanks

    John

  2. #2
    tpl
    tpl is offline
    Linux User
    Join Date
    Jan 2007
    Location
    cleveland
    Posts
    452
    sed 's/:/\n/' <filename
    the sun is new every day (heraclitus)

  3. #3
    Linux User
    Join Date
    Aug 2006
    Posts
    458
    OP wants a transposition.

    @OP, if you have Python
    Code:
    #!/usr/bin/env python
    a=[]
    for line in open("file"):
        line=line.strip().split(" : ")
        a.append(line)
    for i in zip(*a):
        print ' : '.join(i)
    output
    Code:
    # ./test.py
    1 : 2
    A : B

  4. #4
    Linux User saivin's Avatar
    Join Date
    Dec 2008
    Location
    Bengaluru, India
    Posts
    305
    @tpl, not sure if that sed command does the job. may be I tried on wrong file.

    I guess he wants something like:
    Name Id
    A 1234
    B 2343
    C 5656

    converted to:
    Name A B C
    Id 1234 2343 5656

    I tried with above and it did not work.
    A candle looses nothing by lighting other candles. - Khalil Zibran.
    Registered Linux User #490076

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
...