Find entry with maximum value in one column [on hold] Announcing the arrival of Valued Associate #679: Cesar Manara Planned maintenance scheduled April 17/18, 2019 at 00:00UTC (8:00pm US/Eastern) 2019 Community Moderator Election Results Why I closed the “Why is Kali so hard” questionHow can I select columns based on a control file with invalid column numbers?unix: replace one entire column in one file with a single value from another filefind and replace a string in a file without using temp file with SEDAppend a column to a csv file with value from another csv lookup tableHow to join rows with single columns to a maximum of 4 columns in one row?Using AWK to select rows with specific value in specific columnprint each Network set in separate same groupPrint random lines of file but with maximum count of a certain valueFind empty value for any name in fileHow to store output(data) in csv format?
Why is "Consequences inflicted." not a sentence?
Should I discuss the type of campaign with my players?
Why aren't air breathing engines used as small first stages
How do I stop a creek from eroding my steep embankment?
What is the longest distance a 13th-level monk can jump while attacking on the same turn?
Should I call the interviewer directly, if HR aren't responding?
When is phishing education going too far?
Antler Helmet: Can it work?
What do you call a plan that's an alternative plan in case your initial plan fails?
If Jon Snow became King of the Seven Kingdoms what would his regnal number be?
Do I really need recursive chmod to restrict access to a folder?
Can Pao de Queijo, and similar foods, be kosher for Passover?
Using et al. for a last / senior author rather than for a first author
What causes the vertical darker bands in my photo?
What is the musical term for a note that continously plays through a melody?
What happens to sewage if there is no river near by?
3 doors, three guards, one stone
How to recreate this effect in Photoshop?
When to stop saving and start investing?
If 'B is more likely given A', then 'A is more likely given B'
What LEGO pieces have "real-world" functionality?
Did Xerox really develop the first LAN?
How can players work together to take actions that are otherwise impossible?
Is the address of a local variable a constexpr?
Find entry with maximum value in one column [on hold]
Announcing the arrival of Valued Associate #679: Cesar Manara
Planned maintenance scheduled April 17/18, 2019 at 00:00UTC (8:00pm US/Eastern)
2019 Community Moderator Election Results
Why I closed the “Why is Kali so hard” questionHow can I select columns based on a control file with invalid column numbers?unix: replace one entire column in one file with a single value from another filefind and replace a string in a file without using temp file with SEDAppend a column to a csv file with value from another csv lookup tableHow to join rows with single columns to a maximum of 4 columns in one row?Using AWK to select rows with specific value in specific columnprint each Network set in separate same groupPrint random lines of file but with maximum count of a certain valueFind empty value for any name in fileHow to store output(data) in csv format?
.everyoneloves__top-leaderboard:empty,.everyoneloves__mid-leaderboard:empty,.everyoneloves__bot-mid-leaderboard:empty margin-bottom:0;
In the below example I want to only display UID and Process Name in the Access.csv
file which consume the most memory. Write a shell scripts for this goal.
Access.csv
looks like
UID Process Name PID MEMORY
1, A, 11, 90%
2, B, 22, 30%
3, C, 33, 115%
4, D, 44, 45%
text-processing csv
New contributor
put on hold as off-topic by muru, Kusalananda♦ Apr 12 at 14:37
- This question does not appear to be about Unix or Linux within the scope defined in the help center.
|
show 1 more comment
In the below example I want to only display UID and Process Name in the Access.csv
file which consume the most memory. Write a shell scripts for this goal.
Access.csv
looks like
UID Process Name PID MEMORY
1, A, 11, 90%
2, B, 22, 30%
3, C, 33, 115%
4, D, 44, 45%
text-processing csv
New contributor
put on hold as off-topic by muru, Kusalananda♦ Apr 12 at 14:37
- This question does not appear to be about Unix or Linux within the scope defined in the help center.
3
Hello, and welcome to U&L! What have you tried? How did it not work as expected or intended?
– DopeGhoti
Apr 11 at 19:50
I have tried with the awk command to get the columns but i am not able to get maximum memory process.
– Arad Kumari
Apr 11 at 20:01
1
What are you able to get? Please show what you tried with awk.
– jlliagre
Apr 11 at 20:13
Is the empty line and the header (which does not contain any commas) part of the data?
– Kusalananda♦
Apr 12 at 5:35
1
I'm voting to close this question as off-topic because the user has not clarified the question as requested, and we aren't a script writing service.
– Kusalananda♦
Apr 12 at 14:37
|
show 1 more comment
In the below example I want to only display UID and Process Name in the Access.csv
file which consume the most memory. Write a shell scripts for this goal.
Access.csv
looks like
UID Process Name PID MEMORY
1, A, 11, 90%
2, B, 22, 30%
3, C, 33, 115%
4, D, 44, 45%
text-processing csv
New contributor
In the below example I want to only display UID and Process Name in the Access.csv
file which consume the most memory. Write a shell scripts for this goal.
Access.csv
looks like
UID Process Name PID MEMORY
1, A, 11, 90%
2, B, 22, 30%
3, C, 33, 115%
4, D, 44, 45%
text-processing csv
text-processing csv
New contributor
New contributor
edited Apr 12 at 5:33
Kusalananda♦
142k18265440
142k18265440
New contributor
asked Apr 11 at 19:28
Arad KumariArad Kumari
1
1
New contributor
New contributor
put on hold as off-topic by muru, Kusalananda♦ Apr 12 at 14:37
- This question does not appear to be about Unix or Linux within the scope defined in the help center.
put on hold as off-topic by muru, Kusalananda♦ Apr 12 at 14:37
- This question does not appear to be about Unix or Linux within the scope defined in the help center.
3
Hello, and welcome to U&L! What have you tried? How did it not work as expected or intended?
– DopeGhoti
Apr 11 at 19:50
I have tried with the awk command to get the columns but i am not able to get maximum memory process.
– Arad Kumari
Apr 11 at 20:01
1
What are you able to get? Please show what you tried with awk.
– jlliagre
Apr 11 at 20:13
Is the empty line and the header (which does not contain any commas) part of the data?
– Kusalananda♦
Apr 12 at 5:35
1
I'm voting to close this question as off-topic because the user has not clarified the question as requested, and we aren't a script writing service.
– Kusalananda♦
Apr 12 at 14:37
|
show 1 more comment
3
Hello, and welcome to U&L! What have you tried? How did it not work as expected or intended?
– DopeGhoti
Apr 11 at 19:50
I have tried with the awk command to get the columns but i am not able to get maximum memory process.
– Arad Kumari
Apr 11 at 20:01
1
What are you able to get? Please show what you tried with awk.
– jlliagre
Apr 11 at 20:13
Is the empty line and the header (which does not contain any commas) part of the data?
– Kusalananda♦
Apr 12 at 5:35
1
I'm voting to close this question as off-topic because the user has not clarified the question as requested, and we aren't a script writing service.
– Kusalananda♦
Apr 12 at 14:37
3
3
Hello, and welcome to U&L! What have you tried? How did it not work as expected or intended?
– DopeGhoti
Apr 11 at 19:50
Hello, and welcome to U&L! What have you tried? How did it not work as expected or intended?
– DopeGhoti
Apr 11 at 19:50
I have tried with the awk command to get the columns but i am not able to get maximum memory process.
– Arad Kumari
Apr 11 at 20:01
I have tried with the awk command to get the columns but i am not able to get maximum memory process.
– Arad Kumari
Apr 11 at 20:01
1
1
What are you able to get? Please show what you tried with awk.
– jlliagre
Apr 11 at 20:13
What are you able to get? Please show what you tried with awk.
– jlliagre
Apr 11 at 20:13
Is the empty line and the header (which does not contain any commas) part of the data?
– Kusalananda♦
Apr 12 at 5:35
Is the empty line and the header (which does not contain any commas) part of the data?
– Kusalananda♦
Apr 12 at 5:35
1
1
I'm voting to close this question as off-topic because the user has not clarified the question as requested, and we aren't a script writing service.
– Kusalananda♦
Apr 12 at 14:37
I'm voting to close this question as off-topic because the user has not clarified the question as requested, and we aren't a script writing service.
– Kusalananda♦
Apr 12 at 14:37
|
show 1 more comment
3 Answers
3
active
oldest
votes
Try this:
awk '^UID/) print $4,$1,$2' Access.csv | sort | awk ' if (NR == 1) print substr($3,0,(length($3))-1),substr($2,0,(length($2))-1)'
There's probably a way to do this with just one awk command (and no sort command), but I'm still learning awk, and don't really know how to make it print JUST the line that has the largest value in field four, hence my decision to pipe it to sort and have a second awk instance deal with it.
In any case, this should work. If you need to display column headers ("UID, Process"), here's an alternate version:
awk '^UID/) print $4,$1,$2' Access.csv | sort | awk ' if (NR == 1) print "UIDtProcess Namen" substr($3,0,(length($3))-1) "t" substr($2,0,(length($2))-1)'
add a comment |
You can use
sort -nrk4 file | awk -F',' 'BEGINprint("IDtNAMEn") NR== 1 print($1,$2)'
add a comment |
You could do this from a bash command line as shown:
Command-line:
$ perl -F, -lane '
print,next if $. == 1;
$F[-1] > $max and ($L,$max) = ($_,$F[-1]);
} sort print $L;
' input.csv
Results:
UID,Process Name,PID,MEMORY
3,C,33,115%
answered Apr 12 at 6:34
Rakesh SharmaRakesh Sharma
262
262
add a comment |
add a comment |
3
Hello, and welcome to U&L! What have you tried? How did it not work as expected or intended?
– DopeGhoti
Apr 11 at 19:50
I have tried with the awk command to get the columns but i am not able to get maximum memory process.
– Arad Kumari
Apr 11 at 20:01
1
What are you able to get? Please show what you tried with awk.
– jlliagre
Apr 11 at 20:13
Is the empty line and the header (which does not contain any commas) part of the data?
– Kusalananda♦
Apr 12 at 5:35
1
I'm voting to close this question as off-topic because the user has not clarified the question as requested, and we aren't a script writing service.
– Kusalananda♦
Apr 12 at 14:37