Thread: how to get appointed colums?

  1. #1
    Registered User
    Join Date
    Aug 2009
    Posts
    168

    how to get appointed colums?

    file1
    Code:
    1275 14.88 0.51 0.51 Contig_000000006 202 397 (38) rnd-1_family-87#LTR/Gypsy 1019 1214 (214) 5
    269 18.42 5.13 2.56 Contig_000000006 338 415 (20) C rnd-1_family-1089#Unknown (3) 200 121 5
    I want to get the fifth column the sixth column(separated by blank), how can I do ?
    result as follows

    Code:
    Contig_000000006 202
    Contig_000000006 338

  2. #2
    Registered User
    Join Date
    Sep 2006
    Posts
    8,868
    Exactly how you could do it, depends on how you're dealing with these data items, now.

    You might read in the current data, and then write it back out, in the order you want it to be in.

  3. #3
    and the hat of int overfl Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    39,660
    Code:
    awk '{ print $5 $6 }' file.txt
    Just like you would do it in C, except that
    - opening files
    - reading lines
    - splitting into fields
    is all part of AWK, and something you have to do yourself in C.
    If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
    If at first you don't succeed, try writing your phone number on the exam paper.

  4. #4
    Registered User
    Join Date
    Aug 2009
    Posts
    168
    Quote Originally Posted by Adak View Post
    Exactly how you could do it, depends on how you're dealing with these data items, now.

    You might read in the current data, and then write it back out, in the order you want it to be in.
    can I use fscanf function?
    is it efficiency?

  5. #5
    and the hat of int overfl Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    39,660
    Yes,
    and No.
    If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
    If at first you don't succeed, try writing your phone number on the exam paper.

  6. #6
    Registered User
    Join Date
    Sep 2006
    Posts
    8,868
    Without code, it's not practical to give detailed advice. Post your code, and then we can talk "turkey".

    C is efficient, and so is scanf(). The only thing C is less than efficient with, is in certain string handling routines. If you have very long strings, use blocks of memory, and pointers - but it's not as easy as doing it with a language that supports a native string data type.

  7. #7
    Registered User
    Join Date
    Aug 2009
    Posts
    168
    Quote Originally Posted by Adak View Post
    Without code, it's not practical to give detailed advice. Post your code, and then we can talk "turkey".

    C is efficient, and so is scanf(). The only thing C is less than efficient with, is in certain string handling routines. If you have very long strings, use blocks of memory, and pointers - but it's not as easy as doing it with a language that supports a native string data type.
    Code:
    fscanf(fp,"%d %f %f %f %s %d %d %s %s %s %d %d %d %d",&b,&a,&a,&a,r_name,&r_start,&r_end,c,r_fam,c,&b,&b,&b,&b);

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Read colums from a file to inser them in structs
    By IMAC in forum C Programming
    Replies: 1
    Last Post: 03-28-2010, 02:48 PM
  2. displaying with rows and colums
    By tio1225 in forum C++ Programming
    Replies: 1
    Last Post: 09-23-2005, 05:07 PM
  3. Reading colums with tab spaces
    By Nish in forum C Programming
    Replies: 4
    Last Post: 04-14-2005, 10:51 PM
  4. Rows and colums
    By Aluvas in forum C++ Programming
    Replies: 3
    Last Post: 11-14-2002, 10:18 PM