ovatsug25
ovatsug25

Reputation: 8616

removing a column from a delimited file

I am trying to cut and paste together a tab-delimited file and have been using the cut and paste utilities from unix in this manner:

cut -f 1-66 file1 > file1a
cut -f 68- file1  > file1b
paste file1a file1b

However I was wondering if there was a way to do it in Perl/Ruby using the -F command because that probably would be quicker in the long run. For example

perl -F/\\t/ -ane
for every line in document
  for i (0..66) and (67..Last field in line)
    print $[i]
   end
   print \n
end

Upvotes: 2

Views: 1445

Answers (2)

yko
yko

Reputation: 2710

Perl could work this way:

perl -F/\\t/ -ane  'print join("\t", @F[0..66,68..$#F])'

@F contains parts of the string, $#F contains index of last element in @F

Upvotes: 4

Barmar
Barmar

Reputation: 782683

Your original code seems to be missing some redirections.

How about:

cut -f1-66,68- input > output

I think it's unlikely that perl or ruby will be any faster than this.

Upvotes: 4

Related Questions