Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to use cut command in bash to show all columns except those indicated?

Tags:

bash

cut

I need to remove a column from a plain text file. I think this could be done using the inverse of the cut command. I mean, something like this:

If this is my file:

01 Procedimiento_tal retiro aceptado 01 tx1 01 tx2 01 tx3 02 Procedimiento_tal retiro rechazado 02 tx1 02 tx2 02 tx3 03 Procedimiento_tal retiro aceptado 03 tx1 03 tx2 03 tx3 

What can I do to remove the first column with cut and get the following text in bash?:

Procedimiento_tal retiro aceptado tx1 tx2 tx3 Procedimiento_tal retiro rechazado tx1 tx2 tx3 Procedimiento_tal retiro aceptado tx1 tx2 tx3 

Thanks in advance

like image 792
Hermandroid Avatar asked Mar 12 '13 05:03

Hermandroid


People also ask

What is the cut command in bash?

The cut command is used to extract the specific portion of text in a file. Many options can be added to the command to exclude unwanted items. It is mandatory to specify an option in the command otherwise it shows an error.

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(-).


2 Answers

Using cut:

cut -d ' ' -f 2- input-file 

should do what you want.

like image 56
William Pursell Avatar answered Sep 27 '22 21:09

William Pursell


To read infile using ' ' as a delimiter (-d) and put fields (-f) 2 onwards (2-) into file:

cut -d' ' -f2- infile > file 

See man cut for more options.

N.B: This is not bash-specific.

like image 39
Johnsyweb Avatar answered Sep 27 '22 21:09

Johnsyweb