Assign every word from a line to a variableHow can I list the second to last word found in a sequence of statements in awkawk + print lines from the first line until match wordReplace the first word of each line with its MD5use awk with input from a variableHow to assign a multiple line string value to a variable with indentation in a shell script?read the file and assign the values to another fileUnix variable not able to store sql query outputawk: print one line per field-1 value (distinct) where difference “field-2 - field-3” is minimumAdding a column to the start of a .tsv file in a loop?Writing a AWK script by taking the input file as an argument

Asked to Not Use Transactions and to Use A Workaround to Simulate One

Is there any reason to concentrate on the Thunderous Smite spell after using its effects?

What was the ultimate objective of The Party in 1984?

How to make a bold sparkline in Google Sheets?

What's the benefit of prohibiting the use of techniques/language constructs that have not been taught?

Shouldn't countries like Russia and Canada support global warming?

How can I say "I want to" as a short response, omitting the main verb?

Impossible Scrabble Words

Why does the speed of sound decrease at high altitudes although the air density decreases?

What is the mathematical notation for rounding a given number to the nearest integer?

Seven Places at Once - Another Google Earth Challenge?

Permutations in Disguise

If I want an interpretable model, are there methods other than Linear Regression?

Is my sink P-trap too low?

How to control the output voltage of a solid state relay

Bit one of the Intel 8080's Flags register

2000s space film where an alien species has almost wiped out the human race in a war

Is "you will become a subject matter expert" code for "you'll be working on your own 100% of the time"?

Why is it called a stateful and a stateless firewall?

Insight into cavity resonators

How much would a 1 foot tall human weigh?

What is the source of "You can achieve a lot with hate, but even more with love" (Shakespeare?)

Work done by spring force

Are there any “Third Order” acronyms used in space exploration?



Assign every word from a line to a variable


How can I list the second to last word found in a sequence of statements in awkawk + print lines from the first line until match wordReplace the first word of each line with its MD5use awk with input from a variableHow to assign a multiple line string value to a variable with indentation in a shell script?read the file and assign the values to another fileUnix variable not able to store sql query outputawk: print one line per field-1 value (distinct) where difference “field-2 - field-3” is minimumAdding a column to the start of a .tsv file in a loop?Writing a AWK script by taking the input file as an argument






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








3















I am very new to shell programming.
I have a file named quaternary_splitted.csv on macOS.
Every line has 4 words. I want to take every word from each line and assign it to a variable. Please suggest some kind of awk command in for loop

The value of each of those 4 variable I want to use further in my shell program.



Thanks for the help.
Few of the lines from the file:



Ta Cr Mo W 
Nb Cr Mo W
Nb Ta Mo W
Nb Ta Cr W
Nb Ta Cr Mo









share|improve this question









New contributor



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
















  • 1





    Why awk? I mean, awk does this automatically: awk 'print $3' file will print the 3rd field. Is that what you mean, or do you want to do this in the shell?

    – terdon
    8 hours ago

















3















I am very new to shell programming.
I have a file named quaternary_splitted.csv on macOS.
Every line has 4 words. I want to take every word from each line and assign it to a variable. Please suggest some kind of awk command in for loop

The value of each of those 4 variable I want to use further in my shell program.



Thanks for the help.
Few of the lines from the file:



Ta Cr Mo W 
Nb Cr Mo W
Nb Ta Mo W
Nb Ta Cr W
Nb Ta Cr Mo









share|improve this question









New contributor



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
















  • 1





    Why awk? I mean, awk does this automatically: awk 'print $3' file will print the 3rd field. Is that what you mean, or do you want to do this in the shell?

    – terdon
    8 hours ago













3












3








3


1






I am very new to shell programming.
I have a file named quaternary_splitted.csv on macOS.
Every line has 4 words. I want to take every word from each line and assign it to a variable. Please suggest some kind of awk command in for loop

The value of each of those 4 variable I want to use further in my shell program.



Thanks for the help.
Few of the lines from the file:



Ta Cr Mo W 
Nb Cr Mo W
Nb Ta Mo W
Nb Ta Cr W
Nb Ta Cr Mo









share|improve this question









New contributor



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











I am very new to shell programming.
I have a file named quaternary_splitted.csv on macOS.
Every line has 4 words. I want to take every word from each line and assign it to a variable. Please suggest some kind of awk command in for loop

The value of each of those 4 variable I want to use further in my shell program.



Thanks for the help.
Few of the lines from the file:



Ta Cr Mo W 
Nb Cr Mo W
Nb Ta Mo W
Nb Ta Cr W
Nb Ta Cr Mo






shell-script awk






share|improve this question









New contributor



Sufyan 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



Sufyan 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 8 hours ago









terdon

143k35 gold badges294 silver badges472 bronze badges




143k35 gold badges294 silver badges472 bronze badges






New contributor



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








asked 8 hours ago









SufyanSufyan

162 bronze badges




162 bronze badges




New contributor



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




New contributor




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












  • 1





    Why awk? I mean, awk does this automatically: awk 'print $3' file will print the 3rd field. Is that what you mean, or do you want to do this in the shell?

    – terdon
    8 hours ago












  • 1





    Why awk? I mean, awk does this automatically: awk 'print $3' file will print the 3rd field. Is that what you mean, or do you want to do this in the shell?

    – terdon
    8 hours ago







1




1





Why awk? I mean, awk does this automatically: awk 'print $3' file will print the 3rd field. Is that what you mean, or do you want to do this in the shell?

– terdon
8 hours ago





Why awk? I mean, awk does this automatically: awk 'print $3' file will print the 3rd field. Is that what you mean, or do you want to do this in the shell?

– terdon
8 hours ago










1 Answer
1






active

oldest

votes


















5
















You can do this with a while read loop like so:



while read -r col1 col2 col3 col4 trash; do
something with "$col1"
something with "$col2"
something with "$col3"
something with "$col4"
done < /path/to/quaternary_splitted.csv


This will read through each line of quaternary_splitted.csv and set the first column to col1, second column to col2, etc.



The trash parameter is used to catch anything that may be in your file and unwanted.
Say you had a line: Nb Ta Cr W what is this doing here?. Without trash you would get:



col1=Nb
col2=Ta
col3=Cr
col4='W what is this doing here?`





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/4.0/"u003ecc by-sa 4.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
    );



    );







    Sufyan 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%2f541752%2fassign-every-word-from-a-line-to-a-variable%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









    5
















    You can do this with a while read loop like so:



    while read -r col1 col2 col3 col4 trash; do
    something with "$col1"
    something with "$col2"
    something with "$col3"
    something with "$col4"
    done < /path/to/quaternary_splitted.csv


    This will read through each line of quaternary_splitted.csv and set the first column to col1, second column to col2, etc.



    The trash parameter is used to catch anything that may be in your file and unwanted.
    Say you had a line: Nb Ta Cr W what is this doing here?. Without trash you would get:



    col1=Nb
    col2=Ta
    col3=Cr
    col4='W what is this doing here?`





    share|improve this answer





























      5
















      You can do this with a while read loop like so:



      while read -r col1 col2 col3 col4 trash; do
      something with "$col1"
      something with "$col2"
      something with "$col3"
      something with "$col4"
      done < /path/to/quaternary_splitted.csv


      This will read through each line of quaternary_splitted.csv and set the first column to col1, second column to col2, etc.



      The trash parameter is used to catch anything that may be in your file and unwanted.
      Say you had a line: Nb Ta Cr W what is this doing here?. Without trash you would get:



      col1=Nb
      col2=Ta
      col3=Cr
      col4='W what is this doing here?`





      share|improve this answer



























        5














        5










        5









        You can do this with a while read loop like so:



        while read -r col1 col2 col3 col4 trash; do
        something with "$col1"
        something with "$col2"
        something with "$col3"
        something with "$col4"
        done < /path/to/quaternary_splitted.csv


        This will read through each line of quaternary_splitted.csv and set the first column to col1, second column to col2, etc.



        The trash parameter is used to catch anything that may be in your file and unwanted.
        Say you had a line: Nb Ta Cr W what is this doing here?. Without trash you would get:



        col1=Nb
        col2=Ta
        col3=Cr
        col4='W what is this doing here?`





        share|improve this answer













        You can do this with a while read loop like so:



        while read -r col1 col2 col3 col4 trash; do
        something with "$col1"
        something with "$col2"
        something with "$col3"
        something with "$col4"
        done < /path/to/quaternary_splitted.csv


        This will read through each line of quaternary_splitted.csv and set the first column to col1, second column to col2, etc.



        The trash parameter is used to catch anything that may be in your file and unwanted.
        Say you had a line: Nb Ta Cr W what is this doing here?. Without trash you would get:



        col1=Nb
        col2=Ta
        col3=Cr
        col4='W what is this doing here?`






        share|improve this answer












        share|improve this answer



        share|improve this answer










        answered 8 hours ago









        Jesse_bJesse_b

        18.9k3 gold badges46 silver badges88 bronze badges




        18.9k3 gold badges46 silver badges88 bronze badges
























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









            draft saved

            draft discarded

















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












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











            Sufyan 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%2f541752%2fassign-every-word-from-a-line-to-a-variable%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

            Sahara Skak | Bilen | Luke uk diar | NawigatsjuunCommonskategorii: SaharaWikivoyage raisfeerer: Sahara26° N, 13° O

            The fall designs the understood secretary. Looking glass Science Shock Discovery Hot Everybody Loves Raymond Smile 곳 서비스 성실하다 Defas Kaloolon Definition: To combine or impregnate with sulphur or any of its compounds as to sulphurize caoutchouc in vulcanizing Flame colored Reason Useful Thin Help 갖다 유명하다 낙엽 장례식 Country Iron Definition: A fencer a gladiator one who exhibits his skill in the use of the sword Definition: The American black throated bunting Spiza Americana Nostalgic Needy Method to my madness 시키다 평가되다 전부 소설가 우아하다 Argument Tin Feeling Representative Gym Music Gaur Chicken 일쑤 코치 편 학생증 The harbor values the sugar. Vasagle Yammoe Enstatite Definition: Capable of being limited Road Neighborly Five Refer Built Kangaroo 비비다 Degree Release Bargain Horse 하루 형님 유교 석 동부 괴롭히다 경제력

            19. јануар Садржај Догађаји Рођења Смрти Празници и дани сећања Види још Референце Мени за навигацијуу