0

I have a text file that looks like this:

A   B   C   A   B   C   A   B   C   A   B
G   T   C   A   G   T   C   A   G   T   C
A   B   C   A   B   C   A   B   C   A   B
A   B   C   A   B   C   A   B   C   A   B
A   D   E   A   B   D   E   A   B   D   E
A   B   C   A   B   C   A   B   C   A   B
C   B   D   G   C   B   D   G   C   B   D

Is there a way to extract only certain columns and leave the other columns intact?

For example removing only columns 2 and 5:

A   C   A   C   A   B   C   A   B
G   C   A   T   C   A   G   T   C
A   C   A   C   A   B   C   A   B
A   C   A   C   A   B   C   A   B
A   E   A   D   E   A   B   D   E
A   C   A   C   A   B   C   A   B
C   D   G   B   D   G   C   B   D

Thanks in advance.

UPDATE:

Found this answer using awk, but this extract whole "block" of columns and I only want to extract some.

Awk for extracting columns 3 to 5:

awk -F 'FS' 'BEGIN{FS="\t"}{for (i=1; i<=NF-1; i++) if(i<3 || i>5) {printf $i FS};{print $NF}}' input.txt
Todd A. Jacobs
  • 81,402
  • 15
  • 141
  • 199
JM88
  • 457
  • 3
  • 6
  • 11
  • 2
    FAQ. Various `awk` examples exist. Try searching. – devnull Mar 14 '14 at 10:31
  • I just checked the answers using awk, but they only extract "block" of columns, and I want to delete columns that are not necessarily adjacent. – JM88 Mar 14 '14 at 10:45
  • Depending on how many columns you want to print, you can use `print $1,$2,$4,$6,…` but that can be tedious, or something like `$3="";$5="";print $0;` if you don't care about the output format – fredtantini Mar 14 '14 at 10:54

1 Answers1

0

in your case you could do

cat your_file |cut -d ' ' --complement -s -f2,5

where ' ' is the delimiter(in your case the space)