Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

If the last column is equal "R" then... Is it possible? In unix

I need to find the last column from a variable that contains some fields. I need to write something like:

    if [ #the last column = "R" ];
    then
    value=`echo "'$value'"`
    fi

Is it possible?

like image 477
Atlas91 Avatar asked Dec 06 '22 07:12

Atlas91


1 Answers

With awk you can try:

awk '$NF=="R"' <<< "$var"

Test:

$ var="this is a var with last as R"
$ awk '$NF=="R"' <<< "$var"
this is a var with last as R
$ var1="This should not be printed"
$ awk '$NF=="R"' <<< "$var1"
$
like image 180
jaypal singh Avatar answered Feb 20 '23 18:02

jaypal singh