Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

delete a column with awk or sed

Tags:

sed

awk

I have a file with three columns. I would like to delete the 3rd column(in-place editing). How can I do this with awk or sed?

123   abc  22.3 453   abg  56.7 1236  hjg  2.3 

Desired output

123  abc 453  abg 1236 hjg  
like image 760
user2160995 Avatar asked Mar 12 '13 12:03

user2160995


People also ask

How do you delete a column in awk?

Without GNU awk you need a match() + substr() combo or multiple sub() s + vars to remove a middle field.

How do I remove a specific column in Unix?

Use the colrm command to remove specified columns from a file. Input is taken from standard input. Output is sent to standard output. If the command is called with one parameter, the columns of each line from the specified column to the last column are removed.

How do I cut a specific column in Linux?

-c (column): To cut by character use the -c option. This can be a list of numbers separated comma or a range of numbers separated by hyphen(-).


1 Answers

try this short thing:

awk '!($3="")' file 
like image 64
Kent Avatar answered Sep 21 '22 23:09

Kent