41

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

Hermandroid
  • 2,120
  • 4
  • 29
  • 35

4 Answers4

70

Using cut:

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

should do what you want.

William Pursell
  • 204,365
  • 48
  • 270
  • 300
19

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 -specific.

johnsyweb
  • 136,902
  • 23
  • 188
  • 247
17

GNU coreutils cut supports the --complement flag. So if you are using that version of cut you can say:

cut --complement -d' ' -f1 infile

Output:

Procedimiento_tal retiro aceptado
tx1
tx2
tx3
Procedimiento_tal retiro rechazado
tx1
tx2
tx3
Procedimiento_tal retiro aceptado
tx1
tx2
tx3
Thor
  • 45,082
  • 11
  • 119
  • 130
1

Here is a command that works, and that is a bit shorter than everyone's:

cut -b 4- input-file

-b stands for byte, and selects the bytes that will get pasted to the screen.

4- is a part of -b and it means that it will select the 4th character of every row to the last character of every row. the cut command will then paste the selection to the screen.

Flare Cat
  • 591
  • 2
  • 12
  • 24