Created
March 6, 2013 04:51
-
-
Save chenzx/5096815 to your computer and use it in GitHub Desktop.
Cut out specific fields of each line, and re-puts out. Similar to awk's function
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
FIELD_SPLITTER = ' ' #change to '\t', ',', ':' as you need; | |
FIELD_CUT_INDEXS = [0] #Start from 0; | |
File.open(ARGV[0]).each { |line| | |
fields = line.strip.split(FIELD_SPLITTER) | |
cut_fields = [] | |
FIELD_CUT_INDEXS.each{ |index| | |
field = fields[index] | |
cut_fields.push( field ) | |
} | |
puts cut_fields.join(FIELD_SPLITTER) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment