I have a file in which I use a string like <xxxxx> to separate the fields. This was a choice to avoid problems with the comma separated fields and other types of single characters due to the nature of strings in the columns which may contain some of these special characters.

I want to extract the first column. I used:

cat myfile.txt | cut -d '<xxxxx>' -f1 > out.txt

But I got error saying that the delimeter must be a single character. Q: How can I extract the first columns (which is before the first occurrence of <xxxxx>?

  • 1
    CSV has rules for how to deal with fields containing commas and newlines etc. (quote fields, double up internal double quotes). Libraries for working with CSV data are readily available for most languages.
    – Kusalananda
    Commented Mar 17, 2019 at 15:12

1 Answer 1


With awk:

echo "This is it"|awk -F '<xxxxx>' '{print $1}'

Note that the field separator (argument to -F) is a regular expression, so if any characters in the separator are special in regexes, you'll need to escape them.

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .