1

I'm automating a workflow with a bash script on Mac OSX. In this workflow, I'd like to add a command that deletes a header from my table (.txt) file that is tab delimited. It looks as follows:

header1 header2 header3
a       1       
b       2       
c       3       
d       4       
e       5       
f       6       

As you can see, the third column, named header3, is empty.

I've noted this post or this one but I don't understand the arguments.

Could you suggest a line of code that automatically deletes the third column, or (even better) deletes the header called 'header3'?

Community
  • 1
  • 1
Nuss9
  • 425
  • 1
  • 5
  • 12

2 Answers2

1

I found the answer here in Table 2C.

sed s/header3//g input.txt > output.txt
miken32
  • 42,008
  • 16
  • 111
  • 154
Nuss9
  • 425
  • 1
  • 5
  • 12
  • This is not deleting the third column, as requested in the question. You're deleting the word "header3" and nothing more. (If your file always has no values in the third column that, will be sufficient.) The `g` option performs a global delete, which is not necessary here, and calling `sed -i''` will edit the file in place without need for redirection. – miken32 Mar 10 '16 at 18:48
1

awk is designed to work with whitespace-separated text columns:

awk '{print $1 "\t" $2}' input.txt > output.txt
miken32
  • 42,008
  • 16
  • 111
  • 154