Using linux “cut”

The following code takes a file that has 16 columns and outputs a file with 5 of those columns.  Some notes:

  • Don’t use PATH as a variable.  The program won’t work, because PATH is a system variable!
  • Note the C++ style syntax of the loop.  Versions of bash greater than 3.0 allow you to use curly brackets, like: for i in {1..50}.  But when you want to use variables inside the range, you have to do something else, such as my example.  Others are discussed here.
  • The star of this script is the ‘cut’ command.  d tells what delimiter you’d like.  f tells what fields you want to cut.
  • Then there are some simple commands around cut.  ‘cat’ displays the contents of the file.  Then, the | operator pipes the output of cat into the next command, which is cut.  Finally, you then use the > operator to direct the output of this command into a new file.
  • Save this file on the cluster or a Linux system as  Then, to run the code, simply type “sh”


# Cut out only the objective function values from the CBorg output files.


echo "Beginning..."
for ((I=1; I<=$NUM_SEEDS; I++));
 echo "Processing $I"
echo "Totally done."


5 thoughts on “Using linux “cut”

  1. Pingback: Using linux “split” « Pat Reed Group Research Tips Blog

  2. Pingback: Useful Linux commands to handle text files and speed up work | Water Programming: A Collaborative Research Blog

  3. Pingback: Water Programming Blog Guide (Part I) – Water Programming: A Collaborative Research Blog

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )


Connecting to %s