Thread: file processing -- remove the first column of each line

  1. #1
    Registered User
    Join Date
    May 2006
    Posts
    1,579

    file processing -- remove the first column of each line

    Hello everyone,


    I have a text file with a lot of lines, and in each line, there are several columns divided by space character, but the number of columns in each line varies. For example, here is a sample,

    --------------------
    abc 123 234 456
    bsc 3 5 7 9 10 123
    yyt 23
    --------------------

    I want to get a new file based on the existing file, by removing the first column, here is the related output of above sample,

    --------------------
    123 234 456
    3 5 7 9 10 123
    23
    --------------------

    Currently, my program runs on Linux, I am using awk command in my C/C++ program, to print from $2 to $100 by removing the first column of each line (I assume that the number of columns does not exceed 100).

    I think my method is somewhat stupid. Does anyone have better ideas of how to utilize awk or sed or some other utility in my C/C++ program to do the same thing?


    thanks in advance,
    George

  2. #2
    Eager young mind
    Join Date
    Jun 2006
    Posts
    342
    It can be done using the cut command too.
    use the -d option to specify the delimiter , blank in your case and the -f option to specify which field you wish to cut
    In the middle of difficulty, lies opportunity

  3. #3
    and the hat of int overfl Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    39,661
    > I am using awk command in my C/C++ program,
    Why do I get the feeling all your C (or C++) programs are little more than lots of calls to system()?
    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.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. How to do encryption in C
    By sankarv in forum C Programming
    Replies: 33
    Last Post: 12-28-2010, 11:01 AM
  2. gcc link external library
    By spank in forum C Programming
    Replies: 6
    Last Post: 08-08-2007, 03:44 PM
  3. Basic text file encoder
    By Abda92 in forum C Programming
    Replies: 15
    Last Post: 05-22-2007, 01:19 PM
  4. Replies: 3
    Last Post: 03-04-2005, 02:46 PM
  5. Possible circular definition with singleton objects
    By techrolla in forum C++ Programming
    Replies: 3
    Last Post: 12-26-2004, 10:46 AM