Thread: Sorting help!

    #1
  1. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Feb 2011
    Posts
    5
    Rep Power
    0

    Sorting help!


    Hi guys,

    I have a file with the following information format:

    ABC (Environment/Location)
    AAA 1.0 (Version of the OS)
    CCC (chip1)

    ZZZ (Environment/Location)
    YYY 2.3 (Version of the OS)
    XXX (chip2)

    ZZZ (Environment/Location)
    YYY 2.3 (Version of the OS)
    XXX (chip2)

    So, basically there are bunch information on there with this format.

    I want to sort them and output the result with only
    ABC (Environment/Location)
    AAA 1.0 (Version of the OS)
    CCC (chip1)

    However, there are multiple environment with
    AAA 1.0 (Version of the OS)
    CCC (chip1)

    So how can I sort them? I can't figure out a way to do it, I was trying Sed and awk, but I just can't get them to work.

    I not suppose to script it, I can only use the command line to get the desirable output.

    If anyone can tell me how to make a column by using awk, that be very helpful as well!
    Example:
    The current output is...
    A
    B
    C
    In this format, however...
    I want to make them
    A, B, C by using awk


    Any suggestion?

    Thanks!
  2. #2
  3. No Profile Picture
    Contributing User
    Devshed Regular (2000 - 2499 posts)

    Join Date
    Mar 2006
    Posts
    2,449
    Rep Power
    1751
    Not totally following you (maybe I need more coffee ...) but to produce a row of date use printf which, by default, will not print a newline so printf("%s,%s,%s\n",x,y,z) will print variables x, y and z as strings separated by a comma on a single line, then a newline (the \n).
    The moon on the one hand, the dawn on the other:
    The moon is my sister, the dawn is my brother.
    The moon on my left and the dawn on my right.
    My brother, good morning: my sister, good night.
    -- Hilaire Belloc
  4. #3
  5. Contributing User
    Devshed Novice (500 - 999 posts)

    Join Date
    Sep 2006
    Posts
    857
    Rep Power
    388

    Cool


    Originally Posted by Guilty1682
    Hi guys,
    Blah, blah, blah...

    So how can I sort them? I can't figure out a way to do it, I was trying Sed and awk, but I just can't get them to work.
    ...Etc...
    Your requirements are not yet clear, you need to provide a good example of source data and correct expected results based on that data.

    ... not suppose to script it, I can only use the command line to get the desirable output.
    This looks like homework, so what have you coded until now? show us the scripts....

IMN logo majestic logo threadwatch logo seochat tools logo