Two field separators (colon and space) in awkInconsistent field separator behaviour of space in awkAwk field separator bug?Run unix command on awk fieldAWK : the ' ' as field separatorParsing with awk by modifying the field and record separatorscompare files basis two columns and add fieldawk won't use '||' as a field delimiterHow to delete input field in AWK?awk: How to use different field separators, and operate on different columnsAWK fields filtering misses the first field

How did Arya manage to disguise herself?

Unidentified items in bicycle tube repair kit

Applying a function to a nested list

Accidentally deleted the "/usr/share" folder

The barbers paradox first order logic formalization

What are the spoon bit of a spoon and fork bit of a fork called?

Can a cyclic Amine form an Amide?

Is lying to get "gardening leave" fraud?

How to creep the reader out with what seems like a normal person?

LT Spice Voltage Output

What word means "to make something obsolete"?

Visualizing a complicated Region

Hang 20lb projector screen on Hardieplank

Was Hulk present at this event?

How can I fairly adjudicate the effects of height differences on ranged attacks?

Does the time required to copy a spell into a spellbook have to be consecutive, or is that just the cumulative time required?

Historically, were women trained for obligatory wars? Or did they serve some other military function?

I’ve officially counted to infinity!

How did Arya get back her dagger from Sansa?

If an enemy is just below a 10-foot-high ceiling, are they in melee range of a creature on the ground?

When do aircrafts become solarcrafts?

Stark VS Thanos

Who died in the Game of Thrones episode, "The Long Night"?

What happened to Rhaegal?



Two field separators (colon and space) in awk


Inconsistent field separator behaviour of space in awkAwk field separator bug?Run unix command on awk fieldAWK : the ' ' as field separatorParsing with awk by modifying the field and record separatorscompare files basis two columns and add fieldawk won't use '||' as a field delimiterHow to delete input field in AWK?awk: How to use different field separators, and operate on different columnsAWK fields filtering misses the first field






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








8















How can we specify two field separators in awk command when one of them is space? I think this can be done by using an embedded if-else condition in awk, however I am not sure about the exact command.



Sample file is as below:



cat test.txt
Swapnil Engineer 20000
Avinash:Doctor:30000
Dattu GovntJob 50000
Amol:Master:10000


I want to print the second column ($2). Expected output is:



Engineer
Doctor
GovntJob
Master


When I tried to put both space and colon as field seperators, it failed with a syntax error:



awk -F[ :] 'print $2' test.txt
awk: cmd. line:1: :]
awk: cmd. line:1: ^ syntax error


How can we use two field separators and utilize awk functionality?










share|improve this question
























  • In addition to Yeti's answer, remember that the shell splits by unquoted whitespace to create the list of arguments to awk, so instead of -F[ :] (one arg) it got -F[: and ]. This chart is quite handy (note the vertical arrows for single/double quotes).

    – arielCo
    2 days ago











  • Thanks ArielCo, much appreciated!

    – Swapnil Dhule
    22 hours ago

















8















How can we specify two field separators in awk command when one of them is space? I think this can be done by using an embedded if-else condition in awk, however I am not sure about the exact command.



Sample file is as below:



cat test.txt
Swapnil Engineer 20000
Avinash:Doctor:30000
Dattu GovntJob 50000
Amol:Master:10000


I want to print the second column ($2). Expected output is:



Engineer
Doctor
GovntJob
Master


When I tried to put both space and colon as field seperators, it failed with a syntax error:



awk -F[ :] 'print $2' test.txt
awk: cmd. line:1: :]
awk: cmd. line:1: ^ syntax error


How can we use two field separators and utilize awk functionality?










share|improve this question
























  • In addition to Yeti's answer, remember that the shell splits by unquoted whitespace to create the list of arguments to awk, so instead of -F[ :] (one arg) it got -F[: and ]. This chart is quite handy (note the vertical arrows for single/double quotes).

    – arielCo
    2 days ago











  • Thanks ArielCo, much appreciated!

    – Swapnil Dhule
    22 hours ago













8












8








8


1






How can we specify two field separators in awk command when one of them is space? I think this can be done by using an embedded if-else condition in awk, however I am not sure about the exact command.



Sample file is as below:



cat test.txt
Swapnil Engineer 20000
Avinash:Doctor:30000
Dattu GovntJob 50000
Amol:Master:10000


I want to print the second column ($2). Expected output is:



Engineer
Doctor
GovntJob
Master


When I tried to put both space and colon as field seperators, it failed with a syntax error:



awk -F[ :] 'print $2' test.txt
awk: cmd. line:1: :]
awk: cmd. line:1: ^ syntax error


How can we use two field separators and utilize awk functionality?










share|improve this question
















How can we specify two field separators in awk command when one of them is space? I think this can be done by using an embedded if-else condition in awk, however I am not sure about the exact command.



Sample file is as below:



cat test.txt
Swapnil Engineer 20000
Avinash:Doctor:30000
Dattu GovntJob 50000
Amol:Master:10000


I want to print the second column ($2). Expected output is:



Engineer
Doctor
GovntJob
Master


When I tried to put both space and colon as field seperators, it failed with a syntax error:



awk -F[ :] 'print $2' test.txt
awk: cmd. line:1: :]
awk: cmd. line:1: ^ syntax error


How can we use two field separators and utilize awk functionality?







awk






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited Apr 26 at 17:32









Jeff Schaller

45.4k1165148




45.4k1165148










asked Apr 26 at 11:21









Swapnil DhuleSwapnil Dhule

855




855












  • In addition to Yeti's answer, remember that the shell splits by unquoted whitespace to create the list of arguments to awk, so instead of -F[ :] (one arg) it got -F[: and ]. This chart is quite handy (note the vertical arrows for single/double quotes).

    – arielCo
    2 days ago











  • Thanks ArielCo, much appreciated!

    – Swapnil Dhule
    22 hours ago

















  • In addition to Yeti's answer, remember that the shell splits by unquoted whitespace to create the list of arguments to awk, so instead of -F[ :] (one arg) it got -F[: and ]. This chart is quite handy (note the vertical arrows for single/double quotes).

    – arielCo
    2 days ago











  • Thanks ArielCo, much appreciated!

    – Swapnil Dhule
    22 hours ago
















In addition to Yeti's answer, remember that the shell splits by unquoted whitespace to create the list of arguments to awk, so instead of -F[ :] (one arg) it got -F[: and ]. This chart is quite handy (note the vertical arrows for single/double quotes).

– arielCo
2 days ago





In addition to Yeti's answer, remember that the shell splits by unquoted whitespace to create the list of arguments to awk, so instead of -F[ :] (one arg) it got -F[: and ]. This chart is quite handy (note the vertical arrows for single/double quotes).

– arielCo
2 days ago













Thanks ArielCo, much appreciated!

– Swapnil Dhule
22 hours ago





Thanks ArielCo, much appreciated!

– Swapnil Dhule
22 hours ago










1 Answer
1






active

oldest

votes


















13














You are on the right track!

Just add the missing quotes around [ :]:



awk -F'[ :]' 'print $2' test.txt
Engineer
Doctor
GovntJob
Master





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%2f515678%2ftwo-field-separators-colon-and-space-in-awk%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









    13














    You are on the right track!

    Just add the missing quotes around [ :]:



    awk -F'[ :]' 'print $2' test.txt
    Engineer
    Doctor
    GovntJob
    Master





    share|improve this answer





























      13














      You are on the right track!

      Just add the missing quotes around [ :]:



      awk -F'[ :]' 'print $2' test.txt
      Engineer
      Doctor
      GovntJob
      Master





      share|improve this answer



























        13












        13








        13







        You are on the right track!

        Just add the missing quotes around [ :]:



        awk -F'[ :]' 'print $2' test.txt
        Engineer
        Doctor
        GovntJob
        Master





        share|improve this answer















        You are on the right track!

        Just add the missing quotes around [ :]:



        awk -F'[ :]' 'print $2' test.txt
        Engineer
        Doctor
        GovntJob
        Master






        share|improve this answer














        share|improve this answer



        share|improve this answer








        edited Apr 26 at 12:16









        Swapnil Dhule

        855




        855










        answered Apr 26 at 11:26









        yetiyeti

        2,55111529




        2,55111529



























            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%2f515678%2ftwo-field-separators-colon-and-space-in-awk%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

            Grendel Contents Story Scholarship Depictions Notes References Navigation menu10.1093/notesj/gjn112Berserkeree

            Area configuration aggregation error after install Porto themeMagento 2.1 CE Installed but front/backend not loading/workingCSS not loading on page within Magento 2 pageCannot install module in Magento 2no commands defined in the “setup” namespace. in Magento2Magento 2: Static files are present but shows 404Why do i have to always run the commands to clean cache in Magento 2.1.8?Failure reason: 'Unable to unserialize value.'Error 500 after magento migrationIn production mode the site does not loadMagento 2 : Error 500 after installing

            Middle Expansion Olielle Resaix Definition: Uttering songs of triumph shouting with joy triumphant exulting Sejunction Journal 붙다 달 고급 품목 외출 The stretch trades the screeching tin. Definition: The act of speaking with a drawl a drawl Cough Sand Definition: An uproar a quarrel a noisy outbreak Shake Iron Publicize Horse House Baby 사과 Resaix Flaggy Jelly Temporary Unequaled Puppet A drop in the bucket Shrew 성격 회원 성질 미팅 The burn frames the tacky quality. Materialistic The smoke reduces the way. Yammoe Nondescript Cheek 얼굴 배 약하다 날리다 타다 The illegal country shows the iron. Help Rule Drearien Smoke Teaching Meaty Wasp Abraham Lincoln Jaws 진심 수리하다 Size Cork Idea Convert Think Lark John Lennon 거울 청소 군 추천하다 아이스크림