Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Deleting columns from a file with awk or from command line on linux

Tags:

How can I delete some columns from a tab separated fields file with awk?

c1 c2 c3 ..... c60 

For example, delete columns between 3 and 29 .

like image 821
user951487 Avatar asked Sep 26 '11 06:09

user951487


People also ask

How do you delete a column in a file in Linux?

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 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. See also Print all but the first three columns. Note: on Ubuntu Trusty GNU Awk 4.0. 1 doesn't have the awk inplace extension enabled by default.

How do I cut a specific column in a Unix file?

1) The cut command is used to display selected parts of file content in UNIX. 2) The default delimiter in cut command is "tab", you can change the delimiter with the option "-d" in the cut command. 3) The cut command in Linux allows you to select the part of the content by bytes, by character, and by field or column.

How do you use awk and cut commands?

You can cut in awk using awk's function split . You can also filter records using a regex condition within awk, making grep and cut superfluous. This breaks down like: Set the output field separator to be a pipe between two spaces.


1 Answers

This is what the cut command is for:

cut -f1,2,30- inputfile 

The default is tab. You can change that with the -d switch.

like image 76
Stephen Darlington Avatar answered Sep 30 '22 10:09

Stephen Darlington