Finding exact string from variable in an awk commmand?2019 Community Moderator ElectionConvert string into date time stamp in gawk or awkUsing ARGV to get user input in Awk scriptHow to use grep/awk/unix to match all lines from one file in another file, even if they are duplicatesHow to use ^#$ as record separator in awk?awk ifs and variables - cannot pass a variable from one line towards subsequent linesFind matches from an index file without exact matching and print the last fieldTrouble with awk matchWhere to get the new string after running `sub` in awkmake awk print the line that match a variable and the next n lines and use a variable in awkPrint between lines 7-13 who contain a certain string (awk script)

Why are all the doors on Ferenginar (the Ferengi home world) far shorter than the average Ferengi?

Installing PowerShell on 32-bit Kali OS fails

Hostile work environment after whistle-blowing on coworker and our boss. What do I do?

Greatest common substring

Is there an wasy way to program in Tikz something like the one in the image?

Simple recursive Sudoku solver

Can a malicious addon access internet history and such in chrome/firefox?

Blender - show edges angles “direction”

Meta programming: Declare a new struct on the fly

Is there an Impartial Brexit Deal comparison site?

How to check participants in at events?

Superhero words!

Teaching indefinite integrals that require special-casing

How to deal with or prevent idle in the test team?

Is it legal to discriminate due to the medicine used to treat a medical condition?

Is there any significance to the Valyrian Stone vault door of Qarth?

Invariance of results when scaling explanatory variables in logistic regression, is there a proof?

I'm in charge of equipment buying but no one's ever happy with what I choose. How to fix this?

Reply ‘no position’ while the job posting is still there (‘HiWi’ position in Germany)

node command while defining a coordinate in TikZ

How can I successfully establish a nationwide combat training program for a large country?

Why does this part of the Space Shuttle launch pad seem to be floating in air?

Latex for-and in equation

What was required to accept "troll"?



Finding exact string from variable in an awk commmand?



2019 Community Moderator ElectionConvert string into date time stamp in gawk or awkUsing ARGV to get user input in Awk scriptHow to use grep/awk/unix to match all lines from one file in another file, even if they are duplicatesHow to use ^#$ as record separator in awk?awk ifs and variables - cannot pass a variable from one line towards subsequent linesFind matches from an index file without exact matching and print the last fieldTrouble with awk matchWhere to get the new string after running `sub` in awkmake awk print the line that match a variable and the next n lines and use a variable in awkPrint between lines 7-13 who contain a certain string (awk script)










0















I'm trying to the use the following awk command to return a user from a file that lists all users on the system but only if the 8th field is empty and they match the user variable (it's being using in a loop):



awk -F':' -v user="$user" 'index($0, user) if ($8=="") print $1' file


My issue currently is that it returns users that contain the string and aren't exact matches. Any way around this?










share|improve this question









New contributor




JaBoyo is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.




















  • Even if you answered the question yourself it would be good to show some sample input and a corresponding username that can be used to reproduce your problem.

    – Bodo
    Mar 22 at 12:22















0















I'm trying to the use the following awk command to return a user from a file that lists all users on the system but only if the 8th field is empty and they match the user variable (it's being using in a loop):



awk -F':' -v user="$user" 'index($0, user) if ($8=="") print $1' file


My issue currently is that it returns users that contain the string and aren't exact matches. Any way around this?










share|improve this question









New contributor




JaBoyo is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.




















  • Even if you answered the question yourself it would be good to show some sample input and a corresponding username that can be used to reproduce your problem.

    – Bodo
    Mar 22 at 12:22













0












0








0








I'm trying to the use the following awk command to return a user from a file that lists all users on the system but only if the 8th field is empty and they match the user variable (it's being using in a loop):



awk -F':' -v user="$user" 'index($0, user) if ($8=="") print $1' file


My issue currently is that it returns users that contain the string and aren't exact matches. Any way around this?










share|improve this question









New contributor




JaBoyo is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.












I'm trying to the use the following awk command to return a user from a file that lists all users on the system but only if the 8th field is empty and they match the user variable (it's being using in a loop):



awk -F':' -v user="$user" 'index($0, user) if ($8=="") print $1' file


My issue currently is that it returns users that contain the string and aren't exact matches. Any way around this?







awk variable






share|improve this question









New contributor




JaBoyo is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.











share|improve this question









New contributor




JaBoyo is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.









share|improve this question




share|improve this question








edited Mar 22 at 12:02









Jeff Schaller

43.8k1161141




43.8k1161141






New contributor




JaBoyo is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.









asked Mar 22 at 11:46









JaBoyoJaBoyo

1




1




New contributor




JaBoyo is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.





New contributor





JaBoyo is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.






JaBoyo is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.












  • Even if you answered the question yourself it would be good to show some sample input and a corresponding username that can be used to reproduce your problem.

    – Bodo
    Mar 22 at 12:22

















  • Even if you answered the question yourself it would be good to show some sample input and a corresponding username that can be used to reproduce your problem.

    – Bodo
    Mar 22 at 12:22
















Even if you answered the question yourself it would be good to show some sample input and a corresponding username that can be used to reproduce your problem.

– Bodo
Mar 22 at 12:22





Even if you answered the question yourself it would be good to show some sample input and a corresponding username that can be used to reproduce your problem.

– Bodo
Mar 22 at 12:22










2 Answers
2






active

oldest

votes


















0














Solved it.



I ended up using:



awk -F':' -v user="$user" '$1 == user if ($8 == "") print $1' file


I'm a silly boy lol






share|improve this answer








New contributor




JaBoyo is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.















  • 4





    Alternatively, awk ... '$1 == user && $8 == "" print $1 '

    – Kusalananda
    Mar 22 at 11:56






  • 1





    It's best to avoid -v and use environment variables instead (and ENVIRON["VARNAME"] in awk) as -v mangles values that contains backslashes. For instance, with user='r157ot', that would return the entry for root as -v would expand that 157 to o

    – Stéphane Chazelas
    Mar 22 at 18:37


















0














above answers are correct...However we can extract the details using the below command.



awk -F ',' 'if ( $9 == "" && $1 =="$user") print $1' file






share|improve this answer








New contributor




Nizam is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.



















    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
    );



    );






    JaBoyo is a new contributor. Be nice, and check out our Code of Conduct.









    draft saved

    draft discarded


















    StackExchange.ready(
    function ()
    StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2funix.stackexchange.com%2fquestions%2f507961%2ffinding-exact-string-from-variable-in-an-awk-commmand%23new-answer', 'question_page');

    );

    Post as a guest















    Required, but never shown

























    2 Answers
    2






    active

    oldest

    votes








    2 Answers
    2






    active

    oldest

    votes









    active

    oldest

    votes






    active

    oldest

    votes









    0














    Solved it.



    I ended up using:



    awk -F':' -v user="$user" '$1 == user if ($8 == "") print $1' file


    I'm a silly boy lol






    share|improve this answer








    New contributor




    JaBoyo is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
    Check out our Code of Conduct.















    • 4





      Alternatively, awk ... '$1 == user && $8 == "" print $1 '

      – Kusalananda
      Mar 22 at 11:56






    • 1





      It's best to avoid -v and use environment variables instead (and ENVIRON["VARNAME"] in awk) as -v mangles values that contains backslashes. For instance, with user='r157ot', that would return the entry for root as -v would expand that 157 to o

      – Stéphane Chazelas
      Mar 22 at 18:37















    0














    Solved it.



    I ended up using:



    awk -F':' -v user="$user" '$1 == user if ($8 == "") print $1' file


    I'm a silly boy lol






    share|improve this answer








    New contributor




    JaBoyo is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
    Check out our Code of Conduct.















    • 4





      Alternatively, awk ... '$1 == user && $8 == "" print $1 '

      – Kusalananda
      Mar 22 at 11:56






    • 1





      It's best to avoid -v and use environment variables instead (and ENVIRON["VARNAME"] in awk) as -v mangles values that contains backslashes. For instance, with user='r157ot', that would return the entry for root as -v would expand that 157 to o

      – Stéphane Chazelas
      Mar 22 at 18:37













    0












    0








    0







    Solved it.



    I ended up using:



    awk -F':' -v user="$user" '$1 == user if ($8 == "") print $1' file


    I'm a silly boy lol






    share|improve this answer








    New contributor




    JaBoyo is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
    Check out our Code of Conduct.










    Solved it.



    I ended up using:



    awk -F':' -v user="$user" '$1 == user if ($8 == "") print $1' file


    I'm a silly boy lol







    share|improve this answer








    New contributor




    JaBoyo is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
    Check out our Code of Conduct.









    share|improve this answer



    share|improve this answer






    New contributor




    JaBoyo is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
    Check out our Code of Conduct.









    answered Mar 22 at 11:53









    JaBoyoJaBoyo

    1




    1




    New contributor




    JaBoyo is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
    Check out our Code of Conduct.





    New contributor





    JaBoyo is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
    Check out our Code of Conduct.






    JaBoyo is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
    Check out our Code of Conduct.







    • 4





      Alternatively, awk ... '$1 == user && $8 == "" print $1 '

      – Kusalananda
      Mar 22 at 11:56






    • 1





      It's best to avoid -v and use environment variables instead (and ENVIRON["VARNAME"] in awk) as -v mangles values that contains backslashes. For instance, with user='r157ot', that would return the entry for root as -v would expand that 157 to o

      – Stéphane Chazelas
      Mar 22 at 18:37












    • 4





      Alternatively, awk ... '$1 == user && $8 == "" print $1 '

      – Kusalananda
      Mar 22 at 11:56






    • 1





      It's best to avoid -v and use environment variables instead (and ENVIRON["VARNAME"] in awk) as -v mangles values that contains backslashes. For instance, with user='r157ot', that would return the entry for root as -v would expand that 157 to o

      – Stéphane Chazelas
      Mar 22 at 18:37







    4




    4





    Alternatively, awk ... '$1 == user && $8 == "" print $1 '

    – Kusalananda
    Mar 22 at 11:56





    Alternatively, awk ... '$1 == user && $8 == "" print $1 '

    – Kusalananda
    Mar 22 at 11:56




    1




    1





    It's best to avoid -v and use environment variables instead (and ENVIRON["VARNAME"] in awk) as -v mangles values that contains backslashes. For instance, with user='r157ot', that would return the entry for root as -v would expand that 157 to o

    – Stéphane Chazelas
    Mar 22 at 18:37





    It's best to avoid -v and use environment variables instead (and ENVIRON["VARNAME"] in awk) as -v mangles values that contains backslashes. For instance, with user='r157ot', that would return the entry for root as -v would expand that 157 to o

    – Stéphane Chazelas
    Mar 22 at 18:37













    0














    above answers are correct...However we can extract the details using the below command.



    awk -F ',' 'if ( $9 == "" && $1 =="$user") print $1' file






    share|improve this answer








    New contributor




    Nizam is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
    Check out our Code of Conduct.
























      0














      above answers are correct...However we can extract the details using the below command.



      awk -F ',' 'if ( $9 == "" && $1 =="$user") print $1' file






      share|improve this answer








      New contributor




      Nizam is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
      Check out our Code of Conduct.






















        0












        0








        0







        above answers are correct...However we can extract the details using the below command.



        awk -F ',' 'if ( $9 == "" && $1 =="$user") print $1' file






        share|improve this answer








        New contributor




        Nizam is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
        Check out our Code of Conduct.










        above answers are correct...However we can extract the details using the below command.



        awk -F ',' 'if ( $9 == "" && $1 =="$user") print $1' file







        share|improve this answer








        New contributor




        Nizam is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
        Check out our Code of Conduct.









        share|improve this answer



        share|improve this answer






        New contributor




        Nizam is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
        Check out our Code of Conduct.









        answered Mar 22 at 18:16









        NizamNizam

        1




        1




        New contributor




        Nizam is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
        Check out our Code of Conduct.





        New contributor





        Nizam is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
        Check out our Code of Conduct.






        Nizam is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
        Check out our Code of Conduct.




















            JaBoyo is a new contributor. Be nice, and check out our Code of Conduct.









            draft saved

            draft discarded


















            JaBoyo is a new contributor. Be nice, and check out our Code of Conduct.












            JaBoyo is a new contributor. Be nice, and check out our Code of Conduct.











            JaBoyo is a new contributor. Be nice, and check out our Code of Conduct.














            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%2f507961%2ffinding-exact-string-from-variable-in-an-awk-commmand%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







            -awk, variable

            Popular posts from this blog

            Creating 100m^2 grid automatically using QGIS?Creating grid constrained within polygon in QGIS?Createing polygon layer from point data using QGIS?Creating vector grid using QGIS?Creating grid polygons from coordinates using R or PythonCreating grid from spatio temporal point data?Creating fields in attributes table using other layers using QGISCreate .shp vector grid in QGISQGIS Creating 4km point grid within polygonsCreate a vector grid over a raster layerVector Grid Creates just one grid

            What is this called? Old film camera viewer?What makes a good film camera?What to do with an old film camera?What should one look for when buying a used film camera?What is the value and age of this pre-1967 Ricoh 35 mm camera?DSLR recommendation, question about old Canon 35mm film Camera & lensesCan anyone identify the silver rangefinder-style camera in this advertisement?What kind of a Polaroid 600-camera is this?Will an old film camera still work even when not used in a very long time?What is this camera / Can I develop the film?How to fit an action camera into antique (bellows) housing?What to check when buying used and old film bodies?

            Why is this plane circling around the Lucknow airport every day?Why do aircraft on Flight Radar 24 jump around randomly sometimes?What airport has this walkway over a taxiway?How does Chicago O'Hare's tower sequence aircraft at peak capacity?Which airport is featured in this Delta commercial?After a crash, for how long is the airport closed?Can a passenger plane stand still in the air, or hover at a fixed location above a ground?What are those trucks towing around, and why?What is this airport outside of Cairo, Egypt?Which US airport has the lowest circling MDH?What is this airport video?