Find the answer to your Linux question:
Results 1 to 4 of 4
Is it possible to take only 1 specific column of a big data file and copy it into a new file i made in vi? I'm trying to make a ...
Enjoy an ad free experience by logging in. Not a member yet? Register.
  1. #1
    LRG
    LRG is offline
    Just Joined!
    Join Date
    Jun 2009
    Location
    New York
    Posts
    12

    [SOLVED] Copying 1column of data file to new file?


    Is it possible to take only 1 specific column of a big data file and copy it into a new file i made in vi? I'm trying to make a graph but that involves moving that one column of data to a new file, because I don't want to use any other column in the graph.

    Thanks


  2. #2
    Linux Newbie
    Join Date
    Mar 2009
    Posts
    228
    Try using awk. Assuming the columns are separated by spaces and let's say you want the 3rd column the command would look like:

    Code:
    awk '{print $3}' filename > newfilename
    If the columns are separated by something other than spaces, let's say commas, then the -F option is needed.

    Code:
    awk -F',' '{print $3}' filename > newfilename

  3. #3
    Linux Newbie egan's Avatar
    Join Date
    Feb 2009
    Location
    Mountain View, CA
    Posts
    132
    Or, you could use cut whose sole purpose is to do such things.

    The equivalents for the above examples of awk would be:
    cut -f 3 < filename > newfilename
    cut -d "," -f 3 < filename > newfilename

  4. #4
    LRG
    LRG is offline
    Just Joined!
    Join Date
    Jun 2009
    Location
    New York
    Posts
    12
    Thank you both so much! it worked, and that's relatively simple, I don't know why I could not find that anywhere.

Posting Permissions

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