awk regex word boundary











up vote
0
down vote

favorite












I have two Linux machines. One is 4.4.12-99, one is 4.4.143. I just ran apt upgrade on them both.



I have an awk statement that contains a regex that works on 4.4.143, but fails on 4.4.12-99. I have searched for days and tried multiple different syntaxes to discover what can be wrong. awk is not failing or complaining, it's just not matching the word boundary. The scripts are the same on each machine and work fine except for this awk statement. On the one that is not working properly, I can cause it to match everything and provide that result.



ip=$(awk -v sUSER="$sUSER" 'BEGIN{gsub(/./,"\.",sUSER)}match($0,/[0-9]+.[0-9]+.[0-9]+.[0-9]+/) && $0 ~ ("[^[:alnum:]]"sUSER"$") && $0 !~ /^$/ && $0 !~ /^#/{print $1}' /etc/hosts )


awk looks into the /etc/hosts file with a variable, $sUSER and tried to match a user to an associated IP address.



I cant figure out what I am doing wrong.










share|improve this question






















  • What is the sample file you are running this on? Give us a proper reproducible example to help us solve your problem
    – Inian
    Nov 21 at 17:26










  • Hello, the sample file is the /etc/hosts file as shown at the end of the awk statement and once again, as is stated, this awk looks into the /etc/hosts file and extracts an IP address for a given username/hostname.
    – WesZ
    Nov 21 at 17:57






  • 1




    @WesZ, your previous thread stackoverflow.com/questions/53353494/… how different it is please do let us know? That thread also you have not informed anyone about what happened, so please don't do so, take questions/problems one by one only
    – RavinderSingh13
    Nov 21 at 18:01










  • It says:Thanks. Hello. I wanted to post my final line of code that provides the correct output. I appreciate all of the help and guidance from those who responded. I wanted to post the final code in case someone in the future can find it useful.
    – WesZ
    Nov 21 at 18:06










  • @WesZ, could you please do let us know if you have taken guidance from my or hek2mgl post. Both are based on different approaches but you should try it out both and let individual know about its status then/.
    – RavinderSingh13
    Nov 21 at 18:08















up vote
0
down vote

favorite












I have two Linux machines. One is 4.4.12-99, one is 4.4.143. I just ran apt upgrade on them both.



I have an awk statement that contains a regex that works on 4.4.143, but fails on 4.4.12-99. I have searched for days and tried multiple different syntaxes to discover what can be wrong. awk is not failing or complaining, it's just not matching the word boundary. The scripts are the same on each machine and work fine except for this awk statement. On the one that is not working properly, I can cause it to match everything and provide that result.



ip=$(awk -v sUSER="$sUSER" 'BEGIN{gsub(/./,"\.",sUSER)}match($0,/[0-9]+.[0-9]+.[0-9]+.[0-9]+/) && $0 ~ ("[^[:alnum:]]"sUSER"$") && $0 !~ /^$/ && $0 !~ /^#/{print $1}' /etc/hosts )


awk looks into the /etc/hosts file with a variable, $sUSER and tried to match a user to an associated IP address.



I cant figure out what I am doing wrong.










share|improve this question






















  • What is the sample file you are running this on? Give us a proper reproducible example to help us solve your problem
    – Inian
    Nov 21 at 17:26










  • Hello, the sample file is the /etc/hosts file as shown at the end of the awk statement and once again, as is stated, this awk looks into the /etc/hosts file and extracts an IP address for a given username/hostname.
    – WesZ
    Nov 21 at 17:57






  • 1




    @WesZ, your previous thread stackoverflow.com/questions/53353494/… how different it is please do let us know? That thread also you have not informed anyone about what happened, so please don't do so, take questions/problems one by one only
    – RavinderSingh13
    Nov 21 at 18:01










  • It says:Thanks. Hello. I wanted to post my final line of code that provides the correct output. I appreciate all of the help and guidance from those who responded. I wanted to post the final code in case someone in the future can find it useful.
    – WesZ
    Nov 21 at 18:06










  • @WesZ, could you please do let us know if you have taken guidance from my or hek2mgl post. Both are based on different approaches but you should try it out both and let individual know about its status then/.
    – RavinderSingh13
    Nov 21 at 18:08













up vote
0
down vote

favorite









up vote
0
down vote

favorite











I have two Linux machines. One is 4.4.12-99, one is 4.4.143. I just ran apt upgrade on them both.



I have an awk statement that contains a regex that works on 4.4.143, but fails on 4.4.12-99. I have searched for days and tried multiple different syntaxes to discover what can be wrong. awk is not failing or complaining, it's just not matching the word boundary. The scripts are the same on each machine and work fine except for this awk statement. On the one that is not working properly, I can cause it to match everything and provide that result.



ip=$(awk -v sUSER="$sUSER" 'BEGIN{gsub(/./,"\.",sUSER)}match($0,/[0-9]+.[0-9]+.[0-9]+.[0-9]+/) && $0 ~ ("[^[:alnum:]]"sUSER"$") && $0 !~ /^$/ && $0 !~ /^#/{print $1}' /etc/hosts )


awk looks into the /etc/hosts file with a variable, $sUSER and tried to match a user to an associated IP address.



I cant figure out what I am doing wrong.










share|improve this question













I have two Linux machines. One is 4.4.12-99, one is 4.4.143. I just ran apt upgrade on them both.



I have an awk statement that contains a regex that works on 4.4.143, but fails on 4.4.12-99. I have searched for days and tried multiple different syntaxes to discover what can be wrong. awk is not failing or complaining, it's just not matching the word boundary. The scripts are the same on each machine and work fine except for this awk statement. On the one that is not working properly, I can cause it to match everything and provide that result.



ip=$(awk -v sUSER="$sUSER" 'BEGIN{gsub(/./,"\.",sUSER)}match($0,/[0-9]+.[0-9]+.[0-9]+.[0-9]+/) && $0 ~ ("[^[:alnum:]]"sUSER"$") && $0 !~ /^$/ && $0 !~ /^#/{print $1}' /etc/hosts )


awk looks into the /etc/hosts file with a variable, $sUSER and tried to match a user to an associated IP address.



I cant figure out what I am doing wrong.







regex bash awk match






share|improve this question













share|improve this question











share|improve this question




share|improve this question










asked Nov 21 at 17:22









WesZ

236




236












  • What is the sample file you are running this on? Give us a proper reproducible example to help us solve your problem
    – Inian
    Nov 21 at 17:26










  • Hello, the sample file is the /etc/hosts file as shown at the end of the awk statement and once again, as is stated, this awk looks into the /etc/hosts file and extracts an IP address for a given username/hostname.
    – WesZ
    Nov 21 at 17:57






  • 1




    @WesZ, your previous thread stackoverflow.com/questions/53353494/… how different it is please do let us know? That thread also you have not informed anyone about what happened, so please don't do so, take questions/problems one by one only
    – RavinderSingh13
    Nov 21 at 18:01










  • It says:Thanks. Hello. I wanted to post my final line of code that provides the correct output. I appreciate all of the help and guidance from those who responded. I wanted to post the final code in case someone in the future can find it useful.
    – WesZ
    Nov 21 at 18:06










  • @WesZ, could you please do let us know if you have taken guidance from my or hek2mgl post. Both are based on different approaches but you should try it out both and let individual know about its status then/.
    – RavinderSingh13
    Nov 21 at 18:08


















  • What is the sample file you are running this on? Give us a proper reproducible example to help us solve your problem
    – Inian
    Nov 21 at 17:26










  • Hello, the sample file is the /etc/hosts file as shown at the end of the awk statement and once again, as is stated, this awk looks into the /etc/hosts file and extracts an IP address for a given username/hostname.
    – WesZ
    Nov 21 at 17:57






  • 1




    @WesZ, your previous thread stackoverflow.com/questions/53353494/… how different it is please do let us know? That thread also you have not informed anyone about what happened, so please don't do so, take questions/problems one by one only
    – RavinderSingh13
    Nov 21 at 18:01










  • It says:Thanks. Hello. I wanted to post my final line of code that provides the correct output. I appreciate all of the help and guidance from those who responded. I wanted to post the final code in case someone in the future can find it useful.
    – WesZ
    Nov 21 at 18:06










  • @WesZ, could you please do let us know if you have taken guidance from my or hek2mgl post. Both are based on different approaches but you should try it out both and let individual know about its status then/.
    – RavinderSingh13
    Nov 21 at 18:08
















What is the sample file you are running this on? Give us a proper reproducible example to help us solve your problem
– Inian
Nov 21 at 17:26




What is the sample file you are running this on? Give us a proper reproducible example to help us solve your problem
– Inian
Nov 21 at 17:26












Hello, the sample file is the /etc/hosts file as shown at the end of the awk statement and once again, as is stated, this awk looks into the /etc/hosts file and extracts an IP address for a given username/hostname.
– WesZ
Nov 21 at 17:57




Hello, the sample file is the /etc/hosts file as shown at the end of the awk statement and once again, as is stated, this awk looks into the /etc/hosts file and extracts an IP address for a given username/hostname.
– WesZ
Nov 21 at 17:57




1




1




@WesZ, your previous thread stackoverflow.com/questions/53353494/… how different it is please do let us know? That thread also you have not informed anyone about what happened, so please don't do so, take questions/problems one by one only
– RavinderSingh13
Nov 21 at 18:01




@WesZ, your previous thread stackoverflow.com/questions/53353494/… how different it is please do let us know? That thread also you have not informed anyone about what happened, so please don't do so, take questions/problems one by one only
– RavinderSingh13
Nov 21 at 18:01












It says:Thanks. Hello. I wanted to post my final line of code that provides the correct output. I appreciate all of the help and guidance from those who responded. I wanted to post the final code in case someone in the future can find it useful.
– WesZ
Nov 21 at 18:06




It says:Thanks. Hello. I wanted to post my final line of code that provides the correct output. I appreciate all of the help and guidance from those who responded. I wanted to post the final code in case someone in the future can find it useful.
– WesZ
Nov 21 at 18:06












@WesZ, could you please do let us know if you have taken guidance from my or hek2mgl post. Both are based on different approaches but you should try it out both and let individual know about its status then/.
– RavinderSingh13
Nov 21 at 18:08




@WesZ, could you please do let us know if you have taken guidance from my or hek2mgl post. Both are based on different approaches but you should try it out both and let individual know about its status then/.
– RavinderSingh13
Nov 21 at 18:08












2 Answers
2






active

oldest

votes

















up vote
0
down vote



accepted










hek2mgl's answer is what you should use.



For your awk question, GNU awk regular expressions are documented here: https://www.gnu.org/software/gnulib/manual/html_node/gnu_002dawk-regular-expression-syntax.html



They use < and > as zero-width word boundary markers, so you can do



gawk -v sUSER="$sUSER" '
BEGIN {
gsub(/./,"\.",sUSER)
ipv4Re = "^[0-9]+(\.[0-9]+){3}$"
sUserRe = "\<" sUSER "\>"
}
/^$/ || /^#/ {next}
$1 ~ ipv4Re && $0 ~ sUserRe {print $1}
' /etc/hosts


(whitespace is nice, you should try using it)





another approach is looping over the fields and using string equality which automatically encompasses word boundaries. This will work with gawk or mawk



awk -v sUSER="$sUSER" '
!/^#/ {for (i=2; i<=NF; i++) if ($i == sUSER) print $1}
' /etc/hosts





share|improve this answer























  • Whitespace is your friend. Indentation solves a lot of debugging, lol
    – Paul Hodges
    Nov 21 at 20:54










  • Hi Glenn - I used this code and my symptoms are the same. I have actually tried using this "awk" statement on 5 different machines, 4 of them it did not work and one it did work. It worked on the one that it always worked on. Do you think maybe there is a missing library or something? Maybe I should try and reinstall awk/mawk/gawk ?? I am really becoming perplexed with this. I have checked syslog and it reports nothing.
    – WesZ
    Nov 22 at 9:47












  • I did note that the word boundaries are a GNU awk feature. GNU awk is not installed by default on some distributions: what awk are you running? And awk errors will not be syslogged.
    – glenn jackman
    Nov 22 at 14:06












  • Well... it seems "Houston.....we have a problem...." The one that works fine is GNU Awk 4.1.3, API: 1.1 (GNU MPFR 3.1.4, GNU MP 6.1.0) and the one that has problems is awk: not an option: --version awk -Wversion 2>/dev/null || awk --version mawk 1.3.3 Nov 1996, Copyright (C) Michael D. Brennan so what should I do?
    – WesZ
    Nov 22 at 16:11










  • So is it gawk that needs to be installed to get the GNU stuff?
    – WesZ
    Nov 22 at 16:18


















up vote
1
down vote













What you basically want to do is a local hostname lookup. There is a tool called getent for that purpose:



getent -s files hosts "${sUSER}" | cut -d' ' -f1


-s files tells getent to only use the local host databases (not DNS) which is /etc/hosts.






share|improve this answer























  • Hello, this getent works, but can it be made to use a specified file? I looked on the man page, but it wasn't mentioned. I can use this, I would need to re-write some code to append the /etc/hosts file. If I can, I would like to use the awk code, although it is becoming a bit clunky... so maybe this is a better solution. Thanks.
    – WesZ
    Nov 21 at 19:03










  • getent hosts is always using /etc/hosts. What you basically want to do is a local hostname lookup. getent -s files is made for that.
    – hek2mgl
    Nov 21 at 19:13













Your Answer






StackExchange.ifUsing("editor", function () {
StackExchange.using("externalEditor", function () {
StackExchange.using("snippets", function () {
StackExchange.snippets.init();
});
});
}, "code-snippets");

StackExchange.ready(function() {
var channelOptions = {
tags: "".split(" "),
id: "1"
};
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',
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
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%2fstackoverflow.com%2fquestions%2f53417522%2fawk-regex-word-boundary%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








up vote
0
down vote



accepted










hek2mgl's answer is what you should use.



For your awk question, GNU awk regular expressions are documented here: https://www.gnu.org/software/gnulib/manual/html_node/gnu_002dawk-regular-expression-syntax.html



They use < and > as zero-width word boundary markers, so you can do



gawk -v sUSER="$sUSER" '
BEGIN {
gsub(/./,"\.",sUSER)
ipv4Re = "^[0-9]+(\.[0-9]+){3}$"
sUserRe = "\<" sUSER "\>"
}
/^$/ || /^#/ {next}
$1 ~ ipv4Re && $0 ~ sUserRe {print $1}
' /etc/hosts


(whitespace is nice, you should try using it)





another approach is looping over the fields and using string equality which automatically encompasses word boundaries. This will work with gawk or mawk



awk -v sUSER="$sUSER" '
!/^#/ {for (i=2; i<=NF; i++) if ($i == sUSER) print $1}
' /etc/hosts





share|improve this answer























  • Whitespace is your friend. Indentation solves a lot of debugging, lol
    – Paul Hodges
    Nov 21 at 20:54










  • Hi Glenn - I used this code and my symptoms are the same. I have actually tried using this "awk" statement on 5 different machines, 4 of them it did not work and one it did work. It worked on the one that it always worked on. Do you think maybe there is a missing library or something? Maybe I should try and reinstall awk/mawk/gawk ?? I am really becoming perplexed with this. I have checked syslog and it reports nothing.
    – WesZ
    Nov 22 at 9:47












  • I did note that the word boundaries are a GNU awk feature. GNU awk is not installed by default on some distributions: what awk are you running? And awk errors will not be syslogged.
    – glenn jackman
    Nov 22 at 14:06












  • Well... it seems "Houston.....we have a problem...." The one that works fine is GNU Awk 4.1.3, API: 1.1 (GNU MPFR 3.1.4, GNU MP 6.1.0) and the one that has problems is awk: not an option: --version awk -Wversion 2>/dev/null || awk --version mawk 1.3.3 Nov 1996, Copyright (C) Michael D. Brennan so what should I do?
    – WesZ
    Nov 22 at 16:11










  • So is it gawk that needs to be installed to get the GNU stuff?
    – WesZ
    Nov 22 at 16:18















up vote
0
down vote



accepted










hek2mgl's answer is what you should use.



For your awk question, GNU awk regular expressions are documented here: https://www.gnu.org/software/gnulib/manual/html_node/gnu_002dawk-regular-expression-syntax.html



They use < and > as zero-width word boundary markers, so you can do



gawk -v sUSER="$sUSER" '
BEGIN {
gsub(/./,"\.",sUSER)
ipv4Re = "^[0-9]+(\.[0-9]+){3}$"
sUserRe = "\<" sUSER "\>"
}
/^$/ || /^#/ {next}
$1 ~ ipv4Re && $0 ~ sUserRe {print $1}
' /etc/hosts


(whitespace is nice, you should try using it)





another approach is looping over the fields and using string equality which automatically encompasses word boundaries. This will work with gawk or mawk



awk -v sUSER="$sUSER" '
!/^#/ {for (i=2; i<=NF; i++) if ($i == sUSER) print $1}
' /etc/hosts





share|improve this answer























  • Whitespace is your friend. Indentation solves a lot of debugging, lol
    – Paul Hodges
    Nov 21 at 20:54










  • Hi Glenn - I used this code and my symptoms are the same. I have actually tried using this "awk" statement on 5 different machines, 4 of them it did not work and one it did work. It worked on the one that it always worked on. Do you think maybe there is a missing library or something? Maybe I should try and reinstall awk/mawk/gawk ?? I am really becoming perplexed with this. I have checked syslog and it reports nothing.
    – WesZ
    Nov 22 at 9:47












  • I did note that the word boundaries are a GNU awk feature. GNU awk is not installed by default on some distributions: what awk are you running? And awk errors will not be syslogged.
    – glenn jackman
    Nov 22 at 14:06












  • Well... it seems "Houston.....we have a problem...." The one that works fine is GNU Awk 4.1.3, API: 1.1 (GNU MPFR 3.1.4, GNU MP 6.1.0) and the one that has problems is awk: not an option: --version awk -Wversion 2>/dev/null || awk --version mawk 1.3.3 Nov 1996, Copyright (C) Michael D. Brennan so what should I do?
    – WesZ
    Nov 22 at 16:11










  • So is it gawk that needs to be installed to get the GNU stuff?
    – WesZ
    Nov 22 at 16:18













up vote
0
down vote



accepted







up vote
0
down vote



accepted






hek2mgl's answer is what you should use.



For your awk question, GNU awk regular expressions are documented here: https://www.gnu.org/software/gnulib/manual/html_node/gnu_002dawk-regular-expression-syntax.html



They use < and > as zero-width word boundary markers, so you can do



gawk -v sUSER="$sUSER" '
BEGIN {
gsub(/./,"\.",sUSER)
ipv4Re = "^[0-9]+(\.[0-9]+){3}$"
sUserRe = "\<" sUSER "\>"
}
/^$/ || /^#/ {next}
$1 ~ ipv4Re && $0 ~ sUserRe {print $1}
' /etc/hosts


(whitespace is nice, you should try using it)





another approach is looping over the fields and using string equality which automatically encompasses word boundaries. This will work with gawk or mawk



awk -v sUSER="$sUSER" '
!/^#/ {for (i=2; i<=NF; i++) if ($i == sUSER) print $1}
' /etc/hosts





share|improve this answer














hek2mgl's answer is what you should use.



For your awk question, GNU awk regular expressions are documented here: https://www.gnu.org/software/gnulib/manual/html_node/gnu_002dawk-regular-expression-syntax.html



They use < and > as zero-width word boundary markers, so you can do



gawk -v sUSER="$sUSER" '
BEGIN {
gsub(/./,"\.",sUSER)
ipv4Re = "^[0-9]+(\.[0-9]+){3}$"
sUserRe = "\<" sUSER "\>"
}
/^$/ || /^#/ {next}
$1 ~ ipv4Re && $0 ~ sUserRe {print $1}
' /etc/hosts


(whitespace is nice, you should try using it)





another approach is looping over the fields and using string equality which automatically encompasses word boundaries. This will work with gawk or mawk



awk -v sUSER="$sUSER" '
!/^#/ {for (i=2; i<=NF; i++) if ($i == sUSER) print $1}
' /etc/hosts






share|improve this answer














share|improve this answer



share|improve this answer








edited Nov 22 at 18:24

























answered Nov 21 at 20:05









glenn jackman

164k26139233




164k26139233












  • Whitespace is your friend. Indentation solves a lot of debugging, lol
    – Paul Hodges
    Nov 21 at 20:54










  • Hi Glenn - I used this code and my symptoms are the same. I have actually tried using this "awk" statement on 5 different machines, 4 of them it did not work and one it did work. It worked on the one that it always worked on. Do you think maybe there is a missing library or something? Maybe I should try and reinstall awk/mawk/gawk ?? I am really becoming perplexed with this. I have checked syslog and it reports nothing.
    – WesZ
    Nov 22 at 9:47












  • I did note that the word boundaries are a GNU awk feature. GNU awk is not installed by default on some distributions: what awk are you running? And awk errors will not be syslogged.
    – glenn jackman
    Nov 22 at 14:06












  • Well... it seems "Houston.....we have a problem...." The one that works fine is GNU Awk 4.1.3, API: 1.1 (GNU MPFR 3.1.4, GNU MP 6.1.0) and the one that has problems is awk: not an option: --version awk -Wversion 2>/dev/null || awk --version mawk 1.3.3 Nov 1996, Copyright (C) Michael D. Brennan so what should I do?
    – WesZ
    Nov 22 at 16:11










  • So is it gawk that needs to be installed to get the GNU stuff?
    – WesZ
    Nov 22 at 16:18


















  • Whitespace is your friend. Indentation solves a lot of debugging, lol
    – Paul Hodges
    Nov 21 at 20:54










  • Hi Glenn - I used this code and my symptoms are the same. I have actually tried using this "awk" statement on 5 different machines, 4 of them it did not work and one it did work. It worked on the one that it always worked on. Do you think maybe there is a missing library or something? Maybe I should try and reinstall awk/mawk/gawk ?? I am really becoming perplexed with this. I have checked syslog and it reports nothing.
    – WesZ
    Nov 22 at 9:47












  • I did note that the word boundaries are a GNU awk feature. GNU awk is not installed by default on some distributions: what awk are you running? And awk errors will not be syslogged.
    – glenn jackman
    Nov 22 at 14:06












  • Well... it seems "Houston.....we have a problem...." The one that works fine is GNU Awk 4.1.3, API: 1.1 (GNU MPFR 3.1.4, GNU MP 6.1.0) and the one that has problems is awk: not an option: --version awk -Wversion 2>/dev/null || awk --version mawk 1.3.3 Nov 1996, Copyright (C) Michael D. Brennan so what should I do?
    – WesZ
    Nov 22 at 16:11










  • So is it gawk that needs to be installed to get the GNU stuff?
    – WesZ
    Nov 22 at 16:18
















Whitespace is your friend. Indentation solves a lot of debugging, lol
– Paul Hodges
Nov 21 at 20:54




Whitespace is your friend. Indentation solves a lot of debugging, lol
– Paul Hodges
Nov 21 at 20:54












Hi Glenn - I used this code and my symptoms are the same. I have actually tried using this "awk" statement on 5 different machines, 4 of them it did not work and one it did work. It worked on the one that it always worked on. Do you think maybe there is a missing library or something? Maybe I should try and reinstall awk/mawk/gawk ?? I am really becoming perplexed with this. I have checked syslog and it reports nothing.
– WesZ
Nov 22 at 9:47






Hi Glenn - I used this code and my symptoms are the same. I have actually tried using this "awk" statement on 5 different machines, 4 of them it did not work and one it did work. It worked on the one that it always worked on. Do you think maybe there is a missing library or something? Maybe I should try and reinstall awk/mawk/gawk ?? I am really becoming perplexed with this. I have checked syslog and it reports nothing.
– WesZ
Nov 22 at 9:47














I did note that the word boundaries are a GNU awk feature. GNU awk is not installed by default on some distributions: what awk are you running? And awk errors will not be syslogged.
– glenn jackman
Nov 22 at 14:06






I did note that the word boundaries are a GNU awk feature. GNU awk is not installed by default on some distributions: what awk are you running? And awk errors will not be syslogged.
– glenn jackman
Nov 22 at 14:06














Well... it seems "Houston.....we have a problem...." The one that works fine is GNU Awk 4.1.3, API: 1.1 (GNU MPFR 3.1.4, GNU MP 6.1.0) and the one that has problems is awk: not an option: --version awk -Wversion 2>/dev/null || awk --version mawk 1.3.3 Nov 1996, Copyright (C) Michael D. Brennan so what should I do?
– WesZ
Nov 22 at 16:11




Well... it seems "Houston.....we have a problem...." The one that works fine is GNU Awk 4.1.3, API: 1.1 (GNU MPFR 3.1.4, GNU MP 6.1.0) and the one that has problems is awk: not an option: --version awk -Wversion 2>/dev/null || awk --version mawk 1.3.3 Nov 1996, Copyright (C) Michael D. Brennan so what should I do?
– WesZ
Nov 22 at 16:11












So is it gawk that needs to be installed to get the GNU stuff?
– WesZ
Nov 22 at 16:18




So is it gawk that needs to be installed to get the GNU stuff?
– WesZ
Nov 22 at 16:18












up vote
1
down vote













What you basically want to do is a local hostname lookup. There is a tool called getent for that purpose:



getent -s files hosts "${sUSER}" | cut -d' ' -f1


-s files tells getent to only use the local host databases (not DNS) which is /etc/hosts.






share|improve this answer























  • Hello, this getent works, but can it be made to use a specified file? I looked on the man page, but it wasn't mentioned. I can use this, I would need to re-write some code to append the /etc/hosts file. If I can, I would like to use the awk code, although it is becoming a bit clunky... so maybe this is a better solution. Thanks.
    – WesZ
    Nov 21 at 19:03










  • getent hosts is always using /etc/hosts. What you basically want to do is a local hostname lookup. getent -s files is made for that.
    – hek2mgl
    Nov 21 at 19:13

















up vote
1
down vote













What you basically want to do is a local hostname lookup. There is a tool called getent for that purpose:



getent -s files hosts "${sUSER}" | cut -d' ' -f1


-s files tells getent to only use the local host databases (not DNS) which is /etc/hosts.






share|improve this answer























  • Hello, this getent works, but can it be made to use a specified file? I looked on the man page, but it wasn't mentioned. I can use this, I would need to re-write some code to append the /etc/hosts file. If I can, I would like to use the awk code, although it is becoming a bit clunky... so maybe this is a better solution. Thanks.
    – WesZ
    Nov 21 at 19:03










  • getent hosts is always using /etc/hosts. What you basically want to do is a local hostname lookup. getent -s files is made for that.
    – hek2mgl
    Nov 21 at 19:13















up vote
1
down vote










up vote
1
down vote









What you basically want to do is a local hostname lookup. There is a tool called getent for that purpose:



getent -s files hosts "${sUSER}" | cut -d' ' -f1


-s files tells getent to only use the local host databases (not DNS) which is /etc/hosts.






share|improve this answer














What you basically want to do is a local hostname lookup. There is a tool called getent for that purpose:



getent -s files hosts "${sUSER}" | cut -d' ' -f1


-s files tells getent to only use the local host databases (not DNS) which is /etc/hosts.







share|improve this answer














share|improve this answer



share|improve this answer








edited Nov 21 at 19:17

























answered Nov 21 at 17:53









hek2mgl

105k13138158




105k13138158












  • Hello, this getent works, but can it be made to use a specified file? I looked on the man page, but it wasn't mentioned. I can use this, I would need to re-write some code to append the /etc/hosts file. If I can, I would like to use the awk code, although it is becoming a bit clunky... so maybe this is a better solution. Thanks.
    – WesZ
    Nov 21 at 19:03










  • getent hosts is always using /etc/hosts. What you basically want to do is a local hostname lookup. getent -s files is made for that.
    – hek2mgl
    Nov 21 at 19:13




















  • Hello, this getent works, but can it be made to use a specified file? I looked on the man page, but it wasn't mentioned. I can use this, I would need to re-write some code to append the /etc/hosts file. If I can, I would like to use the awk code, although it is becoming a bit clunky... so maybe this is a better solution. Thanks.
    – WesZ
    Nov 21 at 19:03










  • getent hosts is always using /etc/hosts. What you basically want to do is a local hostname lookup. getent -s files is made for that.
    – hek2mgl
    Nov 21 at 19:13


















Hello, this getent works, but can it be made to use a specified file? I looked on the man page, but it wasn't mentioned. I can use this, I would need to re-write some code to append the /etc/hosts file. If I can, I would like to use the awk code, although it is becoming a bit clunky... so maybe this is a better solution. Thanks.
– WesZ
Nov 21 at 19:03




Hello, this getent works, but can it be made to use a specified file? I looked on the man page, but it wasn't mentioned. I can use this, I would need to re-write some code to append the /etc/hosts file. If I can, I would like to use the awk code, although it is becoming a bit clunky... so maybe this is a better solution. Thanks.
– WesZ
Nov 21 at 19:03












getent hosts is always using /etc/hosts. What you basically want to do is a local hostname lookup. getent -s files is made for that.
– hek2mgl
Nov 21 at 19:13






getent hosts is always using /etc/hosts. What you basically want to do is a local hostname lookup. getent -s files is made for that.
– hek2mgl
Nov 21 at 19:13




















draft saved

draft discarded




















































Thanks for contributing an answer to Stack Overflow!


  • 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.





Some of your past answers have not been well-received, and you're in danger of being blocked from answering.


Please pay close attention to the following guidance:


  • 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%2fstackoverflow.com%2fquestions%2f53417522%2fawk-regex-word-boundary%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

Contact image not getting when fetch all contact list from iPhone by CNContact

count number of partitions of a set with n elements into k subsets

A CLEAN and SIMPLE way to add appendices to Table of Contents and bookmarks