How to print the content of one of the columns related to the same user just using awk?How to run part of a...
Why is CMYK & PNG not possible?
An employee has low self-confidence, and is performing poorly. How can I help?
Is there an engine that finds the best "practical" move?
Little Endian Number to String Conversion
"Dear Stack Exchange, I am very disappointed in you" - How to construct a strong opening line in a letter?
What does IKEA-like mean?
Reference request: Long-term behaviour of the heat equation for bounded initial data
How to remind myself to lock my doors
Type and strength of a typical chain
Why is matter-antimatter asymmetry surprising, if asymmetry can be generated by a random walk in which particles go into black holes?
Would Anti-Magic Zone Affect Dragon Breath?
Can you use wish to cast a level 9 spell?
How to handle shared mortgage payment if one person can't pay their share?
Can you decide not to sneak into a room after seeing your roll?
Why did the range based for loop specification change in C++17
Prove the inequality is true
Calculate the shadow on earth of a large orbital disk
Sanitise a high score table to remove offensive terms / usernames
How do I weigh a kitchen island to determine what size castors to get?
Is It Possible to Make a Virus That Acts as an Anti-virus?
Is self-defense mutually exclusive of murder?
Why did Batman design Robin's suit with only the underwear without pants?
SQL server backup message
What good is Divine Sense?
How to print the content of one of the columns related to the same user just using awk?
How to run part of a script with reduced privileges?find and replace with the value in another fileMatching two main columns at the same time between files, and paste supplementary columns into the output file when those main columns matchHow to handle a series of paired filesubuntu linux shell scripting changing a column value of a line in textfileHow to find lines with different values in 5th column which share the same 2nd column?Parse output with dynamic col widths and empty fieldsIf line contains pattern, print variable to columnAwk print columns
.everyoneloves__top-leaderboard:empty,.everyoneloves__mid-leaderboard:empty,.everyoneloves__bot-mid-leaderboard:empty{
margin-bottom:0;
}
I have columns like these:
User ColumnA ColumnB ComumnC
abc123 hi hello howdy?
xyz123 Namaste que paso rowdy?
abc123 hi hello bowdy?
I want to write the gawk script which prints the content in column 3 related to just abc123 like the following:
User: abc123
howdy
bowdy
So far I got this:
gawk '/^[a-z]{3}[0-9]{3}/ {
temp=$1
printf ("User: %sn", $1);
printf ("t %sn", $4)
}' $1
But it prints all the user and their content in column C in every line without merging the same user's content in columnC like this.
User: abc123
howdy?
User: xyz123
rowdy?
User: abc123
bowdy?
Any suggestions?
linux awk gawk
New contributor
Prashant Sedhain 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 have columns like these:
User ColumnA ColumnB ComumnC
abc123 hi hello howdy?
xyz123 Namaste que paso rowdy?
abc123 hi hello bowdy?
I want to write the gawk script which prints the content in column 3 related to just abc123 like the following:
User: abc123
howdy
bowdy
So far I got this:
gawk '/^[a-z]{3}[0-9]{3}/ {
temp=$1
printf ("User: %sn", $1);
printf ("t %sn", $4)
}' $1
But it prints all the user and their content in column C in every line without merging the same user's content in columnC like this.
User: abc123
howdy?
User: xyz123
rowdy?
User: abc123
bowdy?
Any suggestions?
linux awk gawk
New contributor
Prashant Sedhain 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 have columns like these:
User ColumnA ColumnB ComumnC
abc123 hi hello howdy?
xyz123 Namaste que paso rowdy?
abc123 hi hello bowdy?
I want to write the gawk script which prints the content in column 3 related to just abc123 like the following:
User: abc123
howdy
bowdy
So far I got this:
gawk '/^[a-z]{3}[0-9]{3}/ {
temp=$1
printf ("User: %sn", $1);
printf ("t %sn", $4)
}' $1
But it prints all the user and their content in column C in every line without merging the same user's content in columnC like this.
User: abc123
howdy?
User: xyz123
rowdy?
User: abc123
bowdy?
Any suggestions?
linux awk gawk
New contributor
Prashant Sedhain is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.
I have columns like these:
User ColumnA ColumnB ComumnC
abc123 hi hello howdy?
xyz123 Namaste que paso rowdy?
abc123 hi hello bowdy?
I want to write the gawk script which prints the content in column 3 related to just abc123 like the following:
User: abc123
howdy
bowdy
So far I got this:
gawk '/^[a-z]{3}[0-9]{3}/ {
temp=$1
printf ("User: %sn", $1);
printf ("t %sn", $4)
}' $1
But it prints all the user and their content in column C in every line without merging the same user's content in columnC like this.
User: abc123
howdy?
User: xyz123
rowdy?
User: abc123
bowdy?
Any suggestions?
linux awk gawk
linux awk gawk
New contributor
Prashant Sedhain is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.
New contributor
Prashant Sedhain is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.
edited 1 hour ago
Prashant Sedhain
New contributor
Prashant Sedhain is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.
asked 1 hour ago
Prashant SedhainPrashant Sedhain
11 bronze badge
11 bronze badge
New contributor
Prashant Sedhain is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.
New contributor
Prashant Sedhain 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
|
1 Answer
1
active
oldest
votes
If you want to aggregate values, you won't be able to simply process lines on the fly - you will need to either save or sort.
For example:
$ awk -F't' '
NR>1 {a[$1] = a[$1] "nt" $4}
END {for(user in a) print "User: " user a[user]}
' filename
User: abc123
howdy?
bowdy?
User: xyz123
rowdy?
If the specific output format isn't a requirement, there are other options such as GNU Datamash:
$ datamash --header-in --sort groupby 1 collapse 4 < filename
abc123 howdy?,bowdy?
xyz123 rowdy?
What does -F mean? And also, can you explain how the code is working for the awk part?
– Prashant Sedhain
27 mins ago
@PrashantSedhain-F't'sets the input field separator to the tab character - I guess I assumed your data was tab-delimited (since otherwiseque pasois 2 columns not 1)
– steeldriver
22 mins ago
Awww I get it now. Now I have a small issue though. Since my original file is space delimited and I have stuff like "Howdy bowdy rowdy" on the fourth column (also delimited by space). How do I print all "howdy bowdy rowdy" like the previous output pattern?
– Prashant Sedhain
17 mins ago
Also, another issue I am having right now is that the output is randomly being printed. I want my program to print the username and their column content in the way they occur in the input file.
– Prashant Sedhain
12 mins ago
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/4.0/"u003ecc by-sa 4.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
});
}
});
Prashant Sedhain 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%2f545009%2fhow-to-print-the-content-of-one-of-the-columns-related-to-the-same-user-just-usi%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
If you want to aggregate values, you won't be able to simply process lines on the fly - you will need to either save or sort.
For example:
$ awk -F't' '
NR>1 {a[$1] = a[$1] "nt" $4}
END {for(user in a) print "User: " user a[user]}
' filename
User: abc123
howdy?
bowdy?
User: xyz123
rowdy?
If the specific output format isn't a requirement, there are other options such as GNU Datamash:
$ datamash --header-in --sort groupby 1 collapse 4 < filename
abc123 howdy?,bowdy?
xyz123 rowdy?
What does -F mean? And also, can you explain how the code is working for the awk part?
– Prashant Sedhain
27 mins ago
@PrashantSedhain-F't'sets the input field separator to the tab character - I guess I assumed your data was tab-delimited (since otherwiseque pasois 2 columns not 1)
– steeldriver
22 mins ago
Awww I get it now. Now I have a small issue though. Since my original file is space delimited and I have stuff like "Howdy bowdy rowdy" on the fourth column (also delimited by space). How do I print all "howdy bowdy rowdy" like the previous output pattern?
– Prashant Sedhain
17 mins ago
Also, another issue I am having right now is that the output is randomly being printed. I want my program to print the username and their column content in the way they occur in the input file.
– Prashant Sedhain
12 mins ago
add a comment
|
If you want to aggregate values, you won't be able to simply process lines on the fly - you will need to either save or sort.
For example:
$ awk -F't' '
NR>1 {a[$1] = a[$1] "nt" $4}
END {for(user in a) print "User: " user a[user]}
' filename
User: abc123
howdy?
bowdy?
User: xyz123
rowdy?
If the specific output format isn't a requirement, there are other options such as GNU Datamash:
$ datamash --header-in --sort groupby 1 collapse 4 < filename
abc123 howdy?,bowdy?
xyz123 rowdy?
What does -F mean? And also, can you explain how the code is working for the awk part?
– Prashant Sedhain
27 mins ago
@PrashantSedhain-F't'sets the input field separator to the tab character - I guess I assumed your data was tab-delimited (since otherwiseque pasois 2 columns not 1)
– steeldriver
22 mins ago
Awww I get it now. Now I have a small issue though. Since my original file is space delimited and I have stuff like "Howdy bowdy rowdy" on the fourth column (also delimited by space). How do I print all "howdy bowdy rowdy" like the previous output pattern?
– Prashant Sedhain
17 mins ago
Also, another issue I am having right now is that the output is randomly being printed. I want my program to print the username and their column content in the way they occur in the input file.
– Prashant Sedhain
12 mins ago
add a comment
|
If you want to aggregate values, you won't be able to simply process lines on the fly - you will need to either save or sort.
For example:
$ awk -F't' '
NR>1 {a[$1] = a[$1] "nt" $4}
END {for(user in a) print "User: " user a[user]}
' filename
User: abc123
howdy?
bowdy?
User: xyz123
rowdy?
If the specific output format isn't a requirement, there are other options such as GNU Datamash:
$ datamash --header-in --sort groupby 1 collapse 4 < filename
abc123 howdy?,bowdy?
xyz123 rowdy?
If you want to aggregate values, you won't be able to simply process lines on the fly - you will need to either save or sort.
For example:
$ awk -F't' '
NR>1 {a[$1] = a[$1] "nt" $4}
END {for(user in a) print "User: " user a[user]}
' filename
User: abc123
howdy?
bowdy?
User: xyz123
rowdy?
If the specific output format isn't a requirement, there are other options such as GNU Datamash:
$ datamash --header-in --sort groupby 1 collapse 4 < filename
abc123 howdy?,bowdy?
xyz123 rowdy?
answered 1 hour ago
steeldriversteeldriver
44k5 gold badges57 silver badges97 bronze badges
44k5 gold badges57 silver badges97 bronze badges
What does -F mean? And also, can you explain how the code is working for the awk part?
– Prashant Sedhain
27 mins ago
@PrashantSedhain-F't'sets the input field separator to the tab character - I guess I assumed your data was tab-delimited (since otherwiseque pasois 2 columns not 1)
– steeldriver
22 mins ago
Awww I get it now. Now I have a small issue though. Since my original file is space delimited and I have stuff like "Howdy bowdy rowdy" on the fourth column (also delimited by space). How do I print all "howdy bowdy rowdy" like the previous output pattern?
– Prashant Sedhain
17 mins ago
Also, another issue I am having right now is that the output is randomly being printed. I want my program to print the username and their column content in the way they occur in the input file.
– Prashant Sedhain
12 mins ago
add a comment
|
What does -F mean? And also, can you explain how the code is working for the awk part?
– Prashant Sedhain
27 mins ago
@PrashantSedhain-F't'sets the input field separator to the tab character - I guess I assumed your data was tab-delimited (since otherwiseque pasois 2 columns not 1)
– steeldriver
22 mins ago
Awww I get it now. Now I have a small issue though. Since my original file is space delimited and I have stuff like "Howdy bowdy rowdy" on the fourth column (also delimited by space). How do I print all "howdy bowdy rowdy" like the previous output pattern?
– Prashant Sedhain
17 mins ago
Also, another issue I am having right now is that the output is randomly being printed. I want my program to print the username and their column content in the way they occur in the input file.
– Prashant Sedhain
12 mins ago
What does -F mean? And also, can you explain how the code is working for the awk part?
– Prashant Sedhain
27 mins ago
What does -F mean? And also, can you explain how the code is working for the awk part?
– Prashant Sedhain
27 mins ago
@PrashantSedhain
-F't' sets the input field separator to the tab character - I guess I assumed your data was tab-delimited (since otherwise que paso is 2 columns not 1)– steeldriver
22 mins ago
@PrashantSedhain
-F't' sets the input field separator to the tab character - I guess I assumed your data was tab-delimited (since otherwise que paso is 2 columns not 1)– steeldriver
22 mins ago
Awww I get it now. Now I have a small issue though. Since my original file is space delimited and I have stuff like "Howdy bowdy rowdy" on the fourth column (also delimited by space). How do I print all "howdy bowdy rowdy" like the previous output pattern?
– Prashant Sedhain
17 mins ago
Awww I get it now. Now I have a small issue though. Since my original file is space delimited and I have stuff like "Howdy bowdy rowdy" on the fourth column (also delimited by space). How do I print all "howdy bowdy rowdy" like the previous output pattern?
– Prashant Sedhain
17 mins ago
Also, another issue I am having right now is that the output is randomly being printed. I want my program to print the username and their column content in the way they occur in the input file.
– Prashant Sedhain
12 mins ago
Also, another issue I am having right now is that the output is randomly being printed. I want my program to print the username and their column content in the way they occur in the input file.
– Prashant Sedhain
12 mins ago
add a comment
|
Prashant Sedhain is a new contributor. Be nice, and check out our Code of Conduct.
Prashant Sedhain is a new contributor. Be nice, and check out our Code of Conduct.
Prashant Sedhain is a new contributor. Be nice, and check out our Code of Conduct.
Prashant Sedhain 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%2f545009%2fhow-to-print-the-content-of-one-of-the-columns-related-to-the-same-user-just-usi%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