How to extract the first column in a file with multi-character delimeter?

The name of the pictureThe name of the pictureThe name of the pictureClash Royale CLAN TAG#URR8PPP





.everyoneloves__top-leaderboard:empty,.everyoneloves__mid-leaderboard:empty,.everyoneloves__bot-mid-leaderboard:empty margin-bottom:0;








0















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>?










share|improve this question

















  • 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
    Mar 17 at 15:12

















0















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>?










share|improve this question

















  • 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
    Mar 17 at 15:12













0












0








0








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>?










share|improve this question














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>?







sed files string search






share|improve this question













share|improve this question











share|improve this question




share|improve this question










asked Mar 17 at 14:58









user9371654user9371654

31018




31018







  • 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
    Mar 17 at 15:12












  • 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
    Mar 17 at 15:12







1




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
Mar 17 at 15:12





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
Mar 17 at 15:12










1 Answer
1






active

oldest

votes


















2














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.






share|improve this answer

























    Your Answer








    StackExchange.ready(function()
    var channelOptions =
    tags: "".split(" "),
    id: "106"
    ;
    initTagRenderer("".split(" "), "".split(" "), channelOptions);

    StackExchange.using("externalEditor", function()
    // Have to fire editor after snippets, if snippets enabled
    if (StackExchange.settings.snippets.snippetsEnabled)
    StackExchange.using("snippets", function()
    createEditor();
    );

    else
    createEditor();

    );

    function createEditor()
    StackExchange.prepareEditor(
    heartbeatType: 'answer',
    autoActivateHeartbeat: false,
    convertImagesToLinks: false,
    noModals: true,
    showLowRepImageUploadWarning: true,
    reputationToPostImages: null,
    bindNavPrevention: true,
    postfix: "",
    imageUploader:
    brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
    contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
    allowUrls: true
    ,
    onDemand: true,
    discardSelector: ".discard-answer"
    ,immediatelyShowMarkdownHelp:true
    );



    );













    draft saved

    draft discarded


















    StackExchange.ready(
    function ()
    StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2funix.stackexchange.com%2fquestions%2f506825%2fhow-to-extract-the-first-column-in-a-file-with-multi-character-delimeter%23new-answer', 'question_page');

    );

    Post as a guest















    Required, but never shown

























    1 Answer
    1






    active

    oldest

    votes








    1 Answer
    1






    active

    oldest

    votes









    active

    oldest

    votes






    active

    oldest

    votes









    2














    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.






    share|improve this answer





























      2














      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.






      share|improve this answer



























        2












        2








        2







        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.






        share|improve this answer















        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.







        share|improve this answer














        share|improve this answer



        share|improve this answer








        edited Mar 17 at 15:11









        ilkkachu

        63.4k10104181




        63.4k10104181










        answered Mar 17 at 15:05









        JRFergusonJRFerguson

        10.4k32632




        10.4k32632



























            draft saved

            draft discarded
















































            Thanks for contributing an answer to Unix & Linux Stack Exchange!


            • Please be sure to answer the question. Provide details and share your research!

            But avoid


            • Asking for help, clarification, or responding to other answers.

            • Making statements based on opinion; back them up with references or personal experience.

            To learn more, see our tips on writing great answers.




            draft saved


            draft discarded














            StackExchange.ready(
            function ()
            StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2funix.stackexchange.com%2fquestions%2f506825%2fhow-to-extract-the-first-column-in-a-file-with-multi-character-delimeter%23new-answer', 'question_page');

            );

            Post as a guest















            Required, but never shown





















































            Required, but never shown














            Required, but never shown












            Required, but never shown







            Required, but never shown

































            Required, but never shown














            Required, but never shown












            Required, but never shown







            Required, but never shown






            Popular posts from this blog

            Peggy Mitchell

            Palaiologos

            The Forum (Inglewood, California)