Two field separators (colon and space) in awkInconsistent field separator behaviour of space in awkAwk field separator bug?Run unix command on awk fieldAWK : the ' ' as field separatorParsing with awk by modifying the field and record separatorscompare files basis two columns and add fieldawk won't use '||' as a field delimiterHow to delete input field in AWK?awk: How to use different field separators, and operate on different columnsAWK fields filtering misses the first field
How did Arya manage to disguise herself?
Unidentified items in bicycle tube repair kit
Applying a function to a nested list
Accidentally deleted the "/usr/share" folder
The barbers paradox first order logic formalization
What are the spoon bit of a spoon and fork bit of a fork called?
Can a cyclic Amine form an Amide?
Is lying to get "gardening leave" fraud?
How to creep the reader out with what seems like a normal person?
LT Spice Voltage Output
What word means "to make something obsolete"?
Visualizing a complicated Region
Hang 20lb projector screen on Hardieplank
Was Hulk present at this event?
How can I fairly adjudicate the effects of height differences on ranged attacks?
Does the time required to copy a spell into a spellbook have to be consecutive, or is that just the cumulative time required?
Historically, were women trained for obligatory wars? Or did they serve some other military function?
I’ve officially counted to infinity!
How did Arya get back her dagger from Sansa?
If an enemy is just below a 10-foot-high ceiling, are they in melee range of a creature on the ground?
When do aircrafts become solarcrafts?
Stark VS Thanos
Who died in the Game of Thrones episode, "The Long Night"?
What happened to Rhaegal?
Two field separators (colon and space) in awk
Inconsistent field separator behaviour of space in awkAwk field separator bug?Run unix command on awk fieldAWK : the ' ' as field separatorParsing with awk by modifying the field and record separatorscompare files basis two columns and add fieldawk won't use '||' as a field delimiterHow to delete input field in AWK?awk: How to use different field separators, and operate on different columnsAWK fields filtering misses the first field
.everyoneloves__top-leaderboard:empty,.everyoneloves__mid-leaderboard:empty,.everyoneloves__bot-mid-leaderboard:empty margin-bottom:0;
How can we specify two field separators in awk command when one of them is space? I think this can be done by using an embedded if-else condition in awk, however I am not sure about the exact command.
Sample file is as below:
cat test.txt
Swapnil Engineer 20000
Avinash:Doctor:30000
Dattu GovntJob 50000
Amol:Master:10000
I want to print the second column ($2). Expected output is:
Engineer
Doctor
GovntJob
Master
When I tried to put both space and colon as field seperators, it failed with a syntax error:
awk -F[ :] 'print $2' test.txt
awk: cmd. line:1: :]
awk: cmd. line:1: ^ syntax error
How can we use two field separators and utilize awk functionality?
awk
add a comment |
How can we specify two field separators in awk command when one of them is space? I think this can be done by using an embedded if-else condition in awk, however I am not sure about the exact command.
Sample file is as below:
cat test.txt
Swapnil Engineer 20000
Avinash:Doctor:30000
Dattu GovntJob 50000
Amol:Master:10000
I want to print the second column ($2). Expected output is:
Engineer
Doctor
GovntJob
Master
When I tried to put both space and colon as field seperators, it failed with a syntax error:
awk -F[ :] 'print $2' test.txt
awk: cmd. line:1: :]
awk: cmd. line:1: ^ syntax error
How can we use two field separators and utilize awk functionality?
awk
In addition to Yeti's answer, remember that the shell splits by unquoted whitespace to create the list of arguments to awk, so instead of-F[ :](one arg) it got-F[:and]. This chart is quite handy (note the vertical arrows for single/double quotes).
– arielCo
2 days ago
Thanks ArielCo, much appreciated!
– Swapnil Dhule
22 hours ago
add a comment |
How can we specify two field separators in awk command when one of them is space? I think this can be done by using an embedded if-else condition in awk, however I am not sure about the exact command.
Sample file is as below:
cat test.txt
Swapnil Engineer 20000
Avinash:Doctor:30000
Dattu GovntJob 50000
Amol:Master:10000
I want to print the second column ($2). Expected output is:
Engineer
Doctor
GovntJob
Master
When I tried to put both space and colon as field seperators, it failed with a syntax error:
awk -F[ :] 'print $2' test.txt
awk: cmd. line:1: :]
awk: cmd. line:1: ^ syntax error
How can we use two field separators and utilize awk functionality?
awk
How can we specify two field separators in awk command when one of them is space? I think this can be done by using an embedded if-else condition in awk, however I am not sure about the exact command.
Sample file is as below:
cat test.txt
Swapnil Engineer 20000
Avinash:Doctor:30000
Dattu GovntJob 50000
Amol:Master:10000
I want to print the second column ($2). Expected output is:
Engineer
Doctor
GovntJob
Master
When I tried to put both space and colon as field seperators, it failed with a syntax error:
awk -F[ :] 'print $2' test.txt
awk: cmd. line:1: :]
awk: cmd. line:1: ^ syntax error
How can we use two field separators and utilize awk functionality?
awk
awk
edited Apr 26 at 17:32
Jeff Schaller♦
45.4k1165148
45.4k1165148
asked Apr 26 at 11:21
Swapnil DhuleSwapnil Dhule
855
855
In addition to Yeti's answer, remember that the shell splits by unquoted whitespace to create the list of arguments to awk, so instead of-F[ :](one arg) it got-F[:and]. This chart is quite handy (note the vertical arrows for single/double quotes).
– arielCo
2 days ago
Thanks ArielCo, much appreciated!
– Swapnil Dhule
22 hours ago
add a comment |
In addition to Yeti's answer, remember that the shell splits by unquoted whitespace to create the list of arguments to awk, so instead of-F[ :](one arg) it got-F[:and]. This chart is quite handy (note the vertical arrows for single/double quotes).
– arielCo
2 days ago
Thanks ArielCo, much appreciated!
– Swapnil Dhule
22 hours ago
In addition to Yeti's answer, remember that the shell splits by unquoted whitespace to create the list of arguments to awk, so instead of
-F[ :] (one arg) it got -F[: and ]. This chart is quite handy (note the vertical arrows for single/double quotes).– arielCo
2 days ago
In addition to Yeti's answer, remember that the shell splits by unquoted whitespace to create the list of arguments to awk, so instead of
-F[ :] (one arg) it got -F[: and ]. This chart is quite handy (note the vertical arrows for single/double quotes).– arielCo
2 days ago
Thanks ArielCo, much appreciated!
– Swapnil Dhule
22 hours ago
Thanks ArielCo, much appreciated!
– Swapnil Dhule
22 hours ago
add a comment |
1 Answer
1
active
oldest
votes
You are on the right track!
Just add the missing quotes around [ :]:
awk -F'[ :]' 'print $2' test.txt
Engineer
Doctor
GovntJob
Master
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
);
);
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%2f515678%2ftwo-field-separators-colon-and-space-in-awk%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
You are on the right track!
Just add the missing quotes around [ :]:
awk -F'[ :]' 'print $2' test.txt
Engineer
Doctor
GovntJob
Master
add a comment |
You are on the right track!
Just add the missing quotes around [ :]:
awk -F'[ :]' 'print $2' test.txt
Engineer
Doctor
GovntJob
Master
add a comment |
You are on the right track!
Just add the missing quotes around [ :]:
awk -F'[ :]' 'print $2' test.txt
Engineer
Doctor
GovntJob
Master
You are on the right track!
Just add the missing quotes around [ :]:
awk -F'[ :]' 'print $2' test.txt
Engineer
Doctor
GovntJob
Master
edited Apr 26 at 12:16
Swapnil Dhule
855
855
answered Apr 26 at 11:26
yetiyeti
2,55111529
2,55111529
add a comment |
add a comment |
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%2f515678%2ftwo-field-separators-colon-and-space-in-awk%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
In addition to Yeti's answer, remember that the shell splits by unquoted whitespace to create the list of arguments to awk, so instead of
-F[ :](one arg) it got-F[:and]. This chart is quite handy (note the vertical arrows for single/double quotes).– arielCo
2 days ago
Thanks ArielCo, much appreciated!
– Swapnil Dhule
22 hours ago