Skip to content

Instantly share code, notes, and snippets.

@louwersj
Created January 17, 2023 20:25
Show Gist options
  • Save louwersj/adfea83bcc0ab6657540480f4718f83c to your computer and use it in GitHub Desktop.
Save louwersj/adfea83bcc0ab6657540480f4718f83c to your computer and use it in GitHub Desktop.
BASH - Remove columns from a file

You can use the command cut to remove specific columns from a file. The basic syntax for removing columns is:

cut -f <column numbers> -d <delimiter> <input file> > <output file>

To remove all columns except the first and third columns from a file that is semicolon-separated, you would use the following command:

cut -f 1,3 -d ';' <input file> > <output file>

This command will take the input file, remove all columns except the first and third, using the semicolon as the delimiter and then write the output to the specified output file.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment