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)
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
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.
add a comment |
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
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
add a comment |
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
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
awk variable
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.
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
add a comment |
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
add a comment |
2 Answers
2
active
oldest
votes
Solved it.
I ended up using:
awk -F':' -v user="$user" '$1 == user if ($8 == "") print $1' file
I'm a silly boy lol
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-vand use environment variables instead (andENVIRON["VARNAME"]inawk) as-vmangles values that contains backslashes. For instance, withuser='r157ot', that would return the entry forrootas-vwould expand that157too
– Stéphane Chazelas
Mar 22 at 18:37
add a comment |
above answers are correct...However we can extract the details using the below command.
awk -F ',' 'if ( $9 == "" && $1 =="$user") print $1' file
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.
add a comment |
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.
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
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
Solved it.
I ended up using:
awk -F':' -v user="$user" '$1 == user if ($8 == "") print $1' file
I'm a silly boy lol
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-vand use environment variables instead (andENVIRON["VARNAME"]inawk) as-vmangles values that contains backslashes. For instance, withuser='r157ot', that would return the entry forrootas-vwould expand that157too
– Stéphane Chazelas
Mar 22 at 18:37
add a comment |
Solved it.
I ended up using:
awk -F':' -v user="$user" '$1 == user if ($8 == "") print $1' file
I'm a silly boy lol
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-vand use environment variables instead (andENVIRON["VARNAME"]inawk) as-vmangles values that contains backslashes. For instance, withuser='r157ot', that would return the entry forrootas-vwould expand that157too
– Stéphane Chazelas
Mar 22 at 18:37
add a comment |
Solved it.
I ended up using:
awk -F':' -v user="$user" '$1 == user if ($8 == "") print $1' file
I'm a silly boy lol
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
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.
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-vand use environment variables instead (andENVIRON["VARNAME"]inawk) as-vmangles values that contains backslashes. For instance, withuser='r157ot', that would return the entry forrootas-vwould expand that157too
– Stéphane Chazelas
Mar 22 at 18:37
add a comment |
4
Alternatively,awk ... '$1 == user && $8 == "" print $1 '
– Kusalananda
Mar 22 at 11:56
1
It's best to avoid-vand use environment variables instead (andENVIRON["VARNAME"]inawk) as-vmangles values that contains backslashes. For instance, withuser='r157ot', that would return the entry forrootas-vwould expand that157too
– 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
add a comment |
above answers are correct...However we can extract the details using the below command.
awk -F ',' 'if ( $9 == "" && $1 =="$user") print $1' file
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.
add a comment |
above answers are correct...However we can extract the details using the below command.
awk -F ',' 'if ( $9 == "" && $1 =="$user") print $1' file
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.
add a comment |
above answers are correct...However we can extract the details using the below command.
awk -F ',' 'if ( $9 == "" && $1 =="$user") print $1' file
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
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.
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.
add a comment |
add a comment |
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.
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.
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
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
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
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
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