How can I store the output of an awk command as a bash script variable? [duplicate]





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







0
















This question already has an answer here:




  • How do I assign the output of a command to a variable?

    1 answer




When operating in the linux terminal I can enter the following: command



'''
awk 'FNR==1 {print$5}' SNextractedstats.txt
'''



To display the value in the first row and fifth column of a text file.



I would like to be able to save this value as a variable in a bash script to be able to do sums and call using Echo, how would I go about doing this?
Thank you










share|improve this question













marked as duplicate by steeldriver bash
Users with the  bash badge can single-handedly close bash questions as duplicates and reopen them as needed.

StackExchange.ready(function() {
if (StackExchange.options.isMobile) return;

$('.dupe-hammer-message-hover:not(.hover-bound)').each(function() {
var $hover = $(this).addClass('hover-bound'),
$msg = $hover.siblings('.dupe-hammer-message');

$hover.hover(
function() {
$hover.showInfoMessage('', {
messageElement: $msg.clone().show(),
transient: false,
position: { my: 'bottom left', at: 'top center', offsetTop: -7 },
dismissable: false,
relativeToBody: true
});
},
function() {
StackExchange.helpers.removeMessages();
}
);
});
});
Apr 3 at 13:12


This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.



















  • tldp,org -> Bash guides

    – Hannu
    Apr 3 at 16:08


















0
















This question already has an answer here:




  • How do I assign the output of a command to a variable?

    1 answer




When operating in the linux terminal I can enter the following: command



'''
awk 'FNR==1 {print$5}' SNextractedstats.txt
'''



To display the value in the first row and fifth column of a text file.



I would like to be able to save this value as a variable in a bash script to be able to do sums and call using Echo, how would I go about doing this?
Thank you










share|improve this question













marked as duplicate by steeldriver bash
Users with the  bash badge can single-handedly close bash questions as duplicates and reopen them as needed.

StackExchange.ready(function() {
if (StackExchange.options.isMobile) return;

$('.dupe-hammer-message-hover:not(.hover-bound)').each(function() {
var $hover = $(this).addClass('hover-bound'),
$msg = $hover.siblings('.dupe-hammer-message');

$hover.hover(
function() {
$hover.showInfoMessage('', {
messageElement: $msg.clone().show(),
transient: false,
position: { my: 'bottom left', at: 'top center', offsetTop: -7 },
dismissable: false,
relativeToBody: true
});
},
function() {
StackExchange.helpers.removeMessages();
}
);
});
});
Apr 3 at 13:12


This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.



















  • tldp,org -> Bash guides

    – Hannu
    Apr 3 at 16:08














0












0








0









This question already has an answer here:




  • How do I assign the output of a command to a variable?

    1 answer




When operating in the linux terminal I can enter the following: command



'''
awk 'FNR==1 {print$5}' SNextractedstats.txt
'''



To display the value in the first row and fifth column of a text file.



I would like to be able to save this value as a variable in a bash script to be able to do sums and call using Echo, how would I go about doing this?
Thank you










share|improve this question















This question already has an answer here:




  • How do I assign the output of a command to a variable?

    1 answer




When operating in the linux terminal I can enter the following: command



'''
awk 'FNR==1 {print$5}' SNextractedstats.txt
'''



To display the value in the first row and fifth column of a text file.



I would like to be able to save this value as a variable in a bash script to be able to do sums and call using Echo, how would I go about doing this?
Thank you





This question already has an answer here:




  • How do I assign the output of a command to a variable?

    1 answer








command-line bash scripts awk






share|improve this question













share|improve this question











share|improve this question




share|improve this question










asked Apr 3 at 12:56









Omar Al-kamilOmar Al-kamil

1




1




marked as duplicate by steeldriver bash
Users with the  bash badge can single-handedly close bash questions as duplicates and reopen them as needed.

StackExchange.ready(function() {
if (StackExchange.options.isMobile) return;

$('.dupe-hammer-message-hover:not(.hover-bound)').each(function() {
var $hover = $(this).addClass('hover-bound'),
$msg = $hover.siblings('.dupe-hammer-message');

$hover.hover(
function() {
$hover.showInfoMessage('', {
messageElement: $msg.clone().show(),
transient: false,
position: { my: 'bottom left', at: 'top center', offsetTop: -7 },
dismissable: false,
relativeToBody: true
});
},
function() {
StackExchange.helpers.removeMessages();
}
);
});
});
Apr 3 at 13:12


This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.









marked as duplicate by steeldriver bash
Users with the  bash badge can single-handedly close bash questions as duplicates and reopen them as needed.

StackExchange.ready(function() {
if (StackExchange.options.isMobile) return;

$('.dupe-hammer-message-hover:not(.hover-bound)').each(function() {
var $hover = $(this).addClass('hover-bound'),
$msg = $hover.siblings('.dupe-hammer-message');

$hover.hover(
function() {
$hover.showInfoMessage('', {
messageElement: $msg.clone().show(),
transient: false,
position: { my: 'bottom left', at: 'top center', offsetTop: -7 },
dismissable: false,
relativeToBody: true
});
},
function() {
StackExchange.helpers.removeMessages();
}
);
});
});
Apr 3 at 13:12


This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.















  • tldp,org -> Bash guides

    – Hannu
    Apr 3 at 16:08



















  • tldp,org -> Bash guides

    – Hannu
    Apr 3 at 16:08

















tldp,org -> Bash guides

– Hannu
Apr 3 at 16:08





tldp,org -> Bash guides

– Hannu
Apr 3 at 16:08










1 Answer
1






active

oldest

votes


















1














Read man bash or https://manpages.ubuntu.com/manpages/bionic/en/man1/bash.1.html an do something like



myvar="$(awk 'FNR==1 {print$5}' SNextractedstats.txt)"





share|improve this answer






























    1 Answer
    1






    active

    oldest

    votes








    1 Answer
    1






    active

    oldest

    votes









    active

    oldest

    votes






    active

    oldest

    votes









    1














    Read man bash or https://manpages.ubuntu.com/manpages/bionic/en/man1/bash.1.html an do something like



    myvar="$(awk 'FNR==1 {print$5}' SNextractedstats.txt)"





    share|improve this answer




























      1














      Read man bash or https://manpages.ubuntu.com/manpages/bionic/en/man1/bash.1.html an do something like



      myvar="$(awk 'FNR==1 {print$5}' SNextractedstats.txt)"





      share|improve this answer


























        1












        1








        1







        Read man bash or https://manpages.ubuntu.com/manpages/bionic/en/man1/bash.1.html an do something like



        myvar="$(awk 'FNR==1 {print$5}' SNextractedstats.txt)"





        share|improve this answer













        Read man bash or https://manpages.ubuntu.com/manpages/bionic/en/man1/bash.1.html an do something like



        myvar="$(awk 'FNR==1 {print$5}' SNextractedstats.txt)"






        share|improve this answer












        share|improve this answer



        share|improve this answer










        answered Apr 3 at 13:14









        waltinatorwaltinator

        23.1k74269




        23.1k74269















            Popular posts from this blog

            How did Captain America manage to do this?

            迪纳利

            南乌拉尔铁路局