Format Code Now
/

Extract a Column from Text

FV-10

Put -- column: and a number on the first line, paste delimited rows below it, and get just that column back. It handles lists such as 1,3 and ranges such as 2-4.

Runs in your browser. Nothing is uploaded.

First line: -- column: 2 (or 1,3 or 2-4). Then the delimited rows

Extracted columns

How to use it

  1. On the first line type -- column: and the column, for example -- column: 2, -- column: 1,3 or -- column: 2-4.
  2. Paste your rows underneath, separated by commas, tabs, semicolons, pipes or spaces.
  3. Choose the matching delimiter. Tick Skip the first data row to drop a header.
  4. Press Extract, then copy the result or download it.

How columns are chosen

Columns count from 1. A single number gives one column per line. A comma list or a range such as 2-4 gives several columns joined with the same delimiter, in the order you listed them. Without a first-line directive, column 1 is used. If you ask for a column that no row has, you get an error that names the widest row. A row with fewer columns gives an empty value.

Quotes and delimiters

Fields can be wrapped in double quotes, so a comma inside "Smith, Ada" does not split the field, and a pair of quotes inside a quoted field stands for one quote. Quoted fields may span lines. Quotes are recognised only at the start of a field. The output is written without the quotes and adds them again only where the value holds the delimiter, a quote or a line break. Spaces are not trimmed. For the space delimiter, tick the repeated-spaces option to treat runs of spaces as one.

Error messages and what to do

MessageWhat it meansFix
"abc" is not a column number or range. Use -- column: 2 or -- column: 1,3 or -- column: 2-4The directive has something other than numbers and ranges.Use digits, commas and dashes only, for example -- column: 1,3
Columns count from 1, so 0 is not a column.The column number is 0.Start counting at 1.
The quote opened on line 2 is never closed.A field starts with a double quote that has no closing quote.Add the closing quote, or remove the stray one. Line 2 is the line where the quote opened.

Questions people ask

How do I extract a column from a CSV?

Put -- column: 2 on the first line, paste the CSV below it and press Extract with Comma selected. Column 2 comes back, one value per line. Quoted values with commas inside are kept whole.

Can I extract more than one column?

Yes. Use a list such as -- column: 1,3 or a range such as -- column: 2-4. The columns are joined with the delimiter in the order you wrote them.

How do I extract a column from tab separated text?

Choose Tab in the Delimiter list and give the column on the first line. Pasted spreadsheet data is usually tab separated, so this is the usual choice for text copied from a sheet.

Does it work with space separated text like logs?

Yes. Choose Space and tick Treat repeated spaces as one, so columns padded with several spaces line up. Quoted fields still work with a space delimiter.

What if a row has fewer columns than I asked for?

That row gives an empty value for the missing column. You get an error only when no row at all has the column you asked for.

About this tool

The first line is a directive, -- column: followed by a 1-based column number, a comma list such as 1,3, or a range such as 2-4; without it, column 1 is used. Fields can be wrapped in double quotes, which may hold the delimiter, line breaks and doubled quotes (""). Quotes are only recognised at the start of a field. The output has the quotes removed for a single column unless the value needs them, and uses the same delimiter between several columns, adding quotes only where the value needs them. Short rows give an empty value. The tool does not trim spaces or detect the delimiter for you.

Format Code Now: free, no ads, no accounts. Your input stays in your browser.